Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling close() if readyState=0 == error #4

Open
xpepermint opened this issue Jul 3, 2011 · 3 comments
Open

Calling close() if readyState=0 == error #4

xpepermint opened this issue Jul 3, 2011 · 3 comments

Comments

@xpepermint
Copy link

Hey, it is I :)

I think I found something. My app is crashing (waits for 20sec before error popup) if I try to close the connection when it's not opened. So let say I execute

socket.start();
socket.close();

in that case the app will hang and Fore/Wait error will pop up.

So... I'm closing the connection when finishing the activity. User can see the activity for just a sec before it presses the back button and close/abort the connection. If the activity is closed immediately this error pops up if I wait for a few seconds and close the connection everything is working.

Can you tell me what to do in tat case? Do you know how to fix that?

@stellaraccident
Copy link
Contributor

Hmmm, I'm not sure I completely understand what it is you are experiencing. Do you have a stack trace or anything to go from? At a guess I'd say that there must be some field that is not initialized until open and you are getting an NPE, but nothing is jumping out at me in the source. I can say that I am not using it the way you are, so it is possible we are triggering different behavior.

One thing I do see immediately: In the Android implementation, you should not manually call start (sorry - not documented well except in WebSocket.java). Before the constructor returns, it posts a message to the handler that will call start() on the next tick (presumably after you've set everything up).

Given that you are calling it manually, I think the sequence that is actually executing is:

  1. new AndroidWebSocket()
  2. socket.start()
  3. socket.close()
  4. -- Message Processing --
  5. socket.start()

This isn't correct, but it should also be guarding itself from double calls, so I'm not seeing immediately where the error could be coming from. A stack trace should help pinpoint it.

@xpepermint
Copy link
Author

Hey... no. 4... hum... can't do this to a user :). Sometimes you just want to close and forget.

@stellaraccident
Copy link
Contributor

You should be able to close and forget. If you've got any further details on the error I can try to track it down...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants