File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
src/main/java/org/java_websocket/client Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -339,7 +339,13 @@ private void reset() {
339
339
"You cannot initialize a reconnect out of the websocket thread. Use reconnect in another thread to ensure a successful cleanup." );
340
340
}
341
341
try {
342
+ // This socket null check ensures we can reconnect a socket that failed to connect. It's an uncommon edge case, but we want to make sure we support it
343
+ if (engine .getReadyState () == ReadyState .NOT_YET_CONNECTED && socket != null ) {
344
+ // Closing the socket when we have not connected prevents the writeThread from hanging on a write indefinitely during connection teardown
345
+ socket .close ();
346
+ }
342
347
closeBlocking ();
348
+
343
349
if (writeThread != null ) {
344
350
this .writeThread .interrupt ();
345
351
this .writeThread .join ();
@@ -401,7 +407,13 @@ public boolean connectBlocking() throws InterruptedException {
401
407
*/
402
408
public boolean connectBlocking (long timeout , TimeUnit timeUnit ) throws InterruptedException {
403
409
connect ();
404
- return connectLatch .await (timeout , timeUnit ) && engine .isOpen ();
410
+
411
+ boolean connected = connectLatch .await (timeout , timeUnit );
412
+ if (!connected ) {
413
+ reset ();
414
+ }
415
+
416
+ return connected && engine .isOpen ();
405
417
}
406
418
407
419
/**
You can’t perform that action at this time.
0 commit comments