Gottox / socket.io-java-client

Socket.IO Client Implementation in Java
MIT License
952 stars 387 forks source link

Fix for IllegalStateException: Timer was canceled #44

Open downtownallday opened 11 years ago

downtownallday commented 11 years ago

Apparently cleanup() is called before transportDisconnected() and the second cleanup() call from reconnect() throws the exception. Also, you can't call disconnect() in onError(), or that will also cause a problem (and you don't need to). Hopefully, this will fix the issue:

diff --git "a/C:\\Users\\WxAp\\AppData\\Local\\Temp\\TortoiseGit\\IOCDCF7.tmp\\IOConnection-8f4c6b7-left.java" "b/C:\\ExternalLibs\\sources\\socket.io-java-client\\src\\io\\socket\\IOConnection.java"
index 420d0cc..3dc207b 100644
--- "a/C:\\Users\\WxAp\\AppData\\Local\\Temp\\TortoiseGit\\IOCDCF7.tmp\\IOConnection-8f4c6b7-left.java"
+++ "b/C:\\ExternalLibs\\sources\\socket.io-java-client\\src\\io\\socket\\IOConnection.java"
@@ -555,7 +555,7 @@ class IOConnection implements IOCallback {
     */
    public void transportDisconnected() {
        this.lastException = null;
-       setState(STATE_INTERRUPTED);
+       if (getState() != STATE_INVALID) setState(STATE_INTERRUPTED);
        reconnect();
    }

@@ -568,7 +568,7 @@ class IOConnection implements IOCallback {
     */
    public void transportError(Exception error) {
        this.lastException = error;
-       setState(STATE_INTERRUPTED);
+       if (getState() != STATE_INVALID) setState(STATE_INTERRUPTED);
        reconnect();
    }
qiankanglai commented 11 years ago

WOW! It works!!! Thank you very much!!!

This puzzles me whole night (http://stackoverflow.com/questions/15642784/thread-sleep-cause-exception-in-jmeter-java-request) You saved me a lot of time

daniel-brettschneider commented 11 years ago

This fixes the exception but now there is a thread or something that does not get cancelled and my app does not exit.