Skip to content

Commit d8eb0f8

Browse files
author
Cameron Auser
committed
Ensure the socket is not null when attempting to close it.
1 parent f7d51a8 commit d8eb0f8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main/java/org/java_websocket/client/WebSocketClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ private void reset() {
339339
"You cannot initialize a reconnect out of the websocket thread. Use reconnect in another thread to ensure a successful cleanup.");
340340
}
341341
try {
342-
if (engine.getReadyState() == ReadyState.NOT_YET_CONNECTED) {
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
343345
socket.close();
344346
}
345347
closeBlocking();

0 commit comments

Comments
 (0)