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

Hang on reconnectBlocking #1365

Closed
Xander-Polishchuk opened this issue Oct 18, 2023 · 8 comments
Closed

Hang on reconnectBlocking #1365

Xander-Polishchuk opened this issue Oct 18, 2023 · 8 comments
Assignees
Milestone

Comments

@Xander-Polishchuk
Copy link

Describe the bug
Sometime WebSocketClient hangs on reconnectBlocking() at WebSocketClient.java:422 on closeLatch.await(). That happens very occasionally.

To Reproduce
Steps to reproduce the behavior:

  1. Setup server and client
  2. Connect to Server
  3. call reconnectBlocking() in a loop

Expected behavior
reconnectBlocking() should never hang

Debug log
The only log:

11:36:42.216 [WebSocketConnectReadThread-5820] TRACE org.java_websocket.WebSocketImpl -- write(171): GET / HTTP/1.1
Connection: Upgrade
Host: localhost:41516
Sec-WebSocket-Key: HGF5XrGAw3IBiWJKCnLPTA==
Sec-WebSocket-Version: 13
Upgrade: websocket


11:36:42.222 [WebSocketConnectReadThread-5820] TRACE org.java_websocket.WebSocketImpl -- process(148): (HTTP/1.1 101 Switching Protocols
Content-Length: 0
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Accept: TfhKZHYT6wDgMrIvABVEeUyEBiw=

)
11:36:42.222 [WebSocketConnectReadThread-5820] TRACE o.java_websocket.drafts.Draft_6455 -- acceptHandshakeAsClient - Matching extension found: DefaultExtension
11:36:42.222 [WebSocketConnectReadThread-5820] TRACE o.java_websocket.drafts.Draft_6455 -- acceptHandshake - Matching protocol found: 
11:36:42.222 [WebSocketConnectReadThread-5820] TRACE org.java_websocket.WebSocketImpl -- open using draft: Draft_6455 extension: DefaultExtension protocol:  max frame size: 2147483647
11:36:42.222 [WebSocketConnectReadThread-5820] TRACE o.java_websocket.AbstractWebSocket -- Connection lost timer started
"Test worker@1" prio=5 tid=0x1 nid=NA waiting
  java.lang.Thread.State: WAITING
	  at jdk.internal.misc.Unsafe.park(Unsafe.java:-1)
	  at java.util.concurrent.locks.LockSupport.park(LockSupport.java:211)
	  at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:715)
	  at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1047)
	  at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:230)
	  at org.java_websocket.client.WebSocketClient.closeBlocking(WebSocketClient.java:422)
	  at org.java_websocket.client.WebSocketClient.reset(WebSocketClient.java:343)
	  at org.java_websocket.client.WebSocketClient.reconnectBlocking(WebSocketClient.java:327)

Environment(please complete the following information):

  • Version used: 1.5.4
  • Java version: 17
  • Operating System and version: Windows 10
@PhilipRoman
Copy link
Collaborator

Thanks for the detailed bug reports. I will try to take a look, most likely next week as I'm very busy right now.

@nilkanth0018
Copy link

nilkanth0018 commented Oct 25, 2023

Facing same issue while connectBlocking() also,

What happened in my case:

When I try to connect first time using connectBlocking(), 4 out of 5 times it gives an error on WebSocketClient.java class Line No: 515, it is not specific error and also it will not go into the catch block, it just step out the method.

while (!isClosing() && !isClosed() && (readBytes = istream.read(rawbuffer)) != -1) {
        engine.decode(ByteBuffer.wrap(rawbuffer, 0, readBytes));
      }

Then I reconnecting using reconnectBlocking()

So in the reset() method, it stuck at Line No: 343 at closeBlocking(), because closeLatch is awaiting at Line No: 422

One more thing when we shutdown the server at that time it throw error on client side. Utill it will hang on awaiting state.

I am also using
Version : 1.5.4
Java version: Adoptium OpenJDK 17
Operating System and version: Windows 10

Can you please, Help!

@nilkanth0018
Copy link

@PhilipRoman any update on this?

@PhilipRoman
Copy link
Collaborator

@nilkanth0018
A few days ago I implemented a fix for a closely related issue (see #1367 )
If possible, could you try building the library from branch reconnect-fix and test if this issue occurs for you? It is simple, just run

mvn package -DskipTests=true

And the jar will appear in target directory

@PhilipRoman PhilipRoman self-assigned this Nov 3, 2023
@Xander-Polishchuk
Copy link
Author

@PhilipRoman Thanks for the fix! I will have a look on this week closer to the end.

@Xander-Polishchuk
Copy link
Author

Xander-Polishchuk commented Nov 29, 2023

@PhilipRoman sorry for delay, tested with the branch and everything seems working a it should be. I don't observe any hangs or NPE. Thanks you for the fix!

@Xander-Polishchuk
Copy link
Author

Hey @PhilipRoman any chance to have a bugfix release with the fix? Thanks!

@PhilipRoman
Copy link
Collaborator

@marci4 does the releases

@marci4 marci4 added this to the Release 1.5.5 milestone Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants