Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Intermittent ConnectThread Exception #8

Closed
dbzhang opened this issue May 21, 2012 · 5 comments
Closed

Intermittent ConnectThread Exception #8

dbzhang opened this issue May 21, 2012 · 5 comments

Comments

@dbzhang
Copy link

dbzhang commented May 21, 2012

I intermittently encounter the following fatal exception after I connect to my server. I've attached the crash logs to help identify the issue. Is there something I'm doing incorrect here?

05-21 16:23:10.367: I/System.out(7412): Connection established
05-21 16:23:10.375: W/dalvikvm(7412): threadid=17: thread exiting with uncaught exception (group=0x4001e560)
05-21 16:23:10.375: E/AndroidRuntime(7412): FATAL EXCEPTION: ConnectThread
05-21 16:23:10.375: E/AndroidRuntime(7412): java.lang.IllegalStateException: TimerTask is canceled
05-21 16:23:10.375: E/AndroidRuntime(7412): at java.util.Timer.scheduleImpl(Timer.java:578)
05-21 16:23:10.375: E/AndroidRuntime(7412): at java.util.Timer.schedule(Timer.java:461)
05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.IOConnection.resetTimeout(IOConnection.java:480)
05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.IOConnection.transportConnected(IOConnection.java:515)
05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.WebsocketTransport.onOpen(WebsocketTransport.java:123)
05-21 16:23:10.375: E/AndroidRuntime(7412): at de.roderick.weberknecht.WebSocketConnection.connect(WebSocketConnection.java:139)
05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.WebsocketTransport.connect(WebsocketTransport.java:129)
05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.IOConnection.connectTransport(IOConnection.java:332)
05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.IOConnection.access$300(IOConnection.java:38)
05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.IOConnection$ConnectThread.run(IOConnection.java:201)

@dbzhang
Copy link
Author

dbzhang commented May 22, 2012

Additionally, I intermittently run into the following fatal exception when I force a disconnect and quickly connect the socket again. I've tried catching these two exceptions in my function containing .connect(new IOCallback{...}); without any luck. Once again, am I doing something wrong here?

05-21 16:38:06.305: W/dalvikvm(7566): threadid=33: thread exiting with uncaught exception (group=0x4001e560)
05-21 16:38:06.305: E/AndroidRuntime(7566): FATAL EXCEPTION: backgroundTimer
05-21 16:38:06.305: E/AndroidRuntime(7566): java.lang.NullPointerException
05-21 16:38:06.305: E/AndroidRuntime(7566): at io.socket.IOConnection.connectTransport(IOConnection.java:323)
05-21 16:38:06.305: E/AndroidRuntime(7566): at io.socket.IOConnection.access$300(IOConnection.java:38)
05-21 16:38:06.305: E/AndroidRuntime(7566): at io.socket.IOConnection$ReconnectTask.run(IOConnection.java:173)
05-21 16:38:06.305: E/AndroidRuntime(7566): at java.util.Timer$TimerImpl.run(Timer.java:284)

@Gottox
Copy link
Owner

Gottox commented May 22, 2012

Can you attach the corresponding output of the server?

About your second post: This could be a bug. Did you create a new instance of SocketIO or reused the old one?
I forgot to document that SocketIO (as well as IOConnections, but they're only used internally) are invalidated once onError() or onDisconnect() is called. Use a fresh instance of SocketIO instead. In any way, the library shouldn't throw an NullpointerException but a RuntimeException when you try to reconnect with an invalidated IOConnection.

@dbzhang
Copy link
Author

dbzhang commented May 22, 2012

Thanks for your quick response. Could you elaborate on what kind of server output you'd like?

As for the second post, my app has two states: one which requires a connection to the node server and one which does not. I force hard connects and disconnects to accomplish this, please let me know if there is a better approach.

When the connection is required:
I create a new instance of SocketIO and call .connect() with all my callback implementations each time the client connects. Sample code:
socket = new SocketIO(socketUrl);
socket.connect(new IOCallback() { ..my implementation.. });

When the connection is unnecessary:
I force a disconnect. SampleCode:
socket.disconnect();
socket = null;

@Gottox
Copy link
Owner

Gottox commented May 22, 2012

socket.io prints per default some status informations to stderr, they could be usefull.

It's ok to disconnect and reconnect to a server, but disconnecting/reconnecting should be done in the same thread, otherwise the state may be inconsistent.

What causes the reconnect error is the mutliton pattern in socket.io-java-client. When a SocketIO client connects to the server, it first looks up if there already is a established IOConnection to the server. If so, it is reused. In that way socket.io needs only one tcp-socket for any example.com/* address. My suspiction is, that the new SocketIO instance finds an IOConnection, which state is currently disconnecting.

May you recheck your issues with current master branch? - Please report if the behavior has changed. especially for your second issue.

@dbzhang
Copy link
Author

dbzhang commented May 22, 2012

Just saw your new changes. I'll update my library and keep you posted on the status for the 2nd issue. Thanks a lot

@Gottox Gottox closed this as completed Aug 6, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants