Skip to content

Hang on reconnectBlocking #1365

Closed
Closed

Description

@Xander-Polishchuk

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

Activity

  1. PhilipRoman commented on Oct 18, 2023

    @PhilipRoman
    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.

  2. nilkanth0018 commented on Oct 25, 2023

    @nilkanth0018

    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!

  3. nilkanth0018 commented on Nov 3, 2023

    @nilkanth0018

    @PhilipRoman any update on this?

  4. PhilipRoman commented on Nov 3, 2023

    @PhilipRoman
    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

  5. self-assigned this
    on Nov 3, 2023
  6. Xander-Polishchuk commented on Nov 6, 2023

    @Xander-Polishchuk
    Author

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

  7. Xander-Polishchuk commented on Nov 29, 2023

    @Xander-Polishchuk
    Author

    @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!

  8. Xander-Polishchuk commented on Dec 11, 2023

    @Xander-Polishchuk
    Author

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

  9. PhilipRoman commented on Dec 16, 2023

    @PhilipRoman
    Collaborator

    @marci4 does the releases

  10. added this to the Release 1.5.5 milestone on Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions