Skip to content

Hang on WebSocketClient.close() - #119

Closed
stiletto wants to merge 1 commit into
TooTallNate:masterfrom
stiletto:master
Closed

stiletto wants to merge 1 commit into
TooTallNate:masterfrom
stiletto:master

Conversation

@stiletto

Copy link
Copy Markdown

I tried to use Java-WebSocket in my Android application, but its background thread hangs with high CPU usage when I call WebSocketClient.close().
After some investigation i found that it hangs because close() sends thread interrupt, but that doesn't lead to closing of channel so IO loop continues to run forever.
I don't know if this is a proper fix, but worked for me.

@Davidiusdadi

Copy link
Copy Markdown
Collaborator

hm as far as can tell the client does neither use WebSocketImpl.this.channel nor WebSocketImpl.this.key.
So you should get a NullPointerException when you call closeConnection witch your changes applied...

I would like to know:

  • was the problem reproducible?
  • did your websocket use wss?
  • do you send messages form outside the callback handles like onMessage?
  • can you tell if there where any stacktraces printed to the console before/during the hang?

@stiletto

Copy link
Copy Markdown
Author

Yes, the problem is reproducible. I use only unencrypted connections and
only receive messages. There were no stacktraces during hang.

Sorry, my "fix" was complete bullshit and worked only because it throwed an
exception that interrupted io-loop.
I will try to find real solution tomorrow.

Davidiusdadi added a commit to Davidiusdadi/Java-WebSocket that referenced this pull request Sep 20, 2012
Davidiusdadi added a commit to Davidiusdadi/Java-WebSocket that referenced this pull request Sep 20, 2012
@Davidiusdadi

Copy link
Copy Markdown
Collaborator

Its a pity that no one noticed this bug before.
It seems like the client thread never got terminated properly unless the server terminates the connection.

@stiletto Thank you very much for reporting this bug!

Those commits fix the problem. Just pull the latest version of my repo.

I am going to merge those commits within the next few days to tootallnate.

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

Successfully merging this pull request may close these issues.

2 participants