Skip to content

Commit

Permalink
Ensure the socket is not null when attempting to close it.
Browse files Browse the repository at this point in the history
  • Loading branch information
ysi-camerona committed Feb 21, 2024
1 parent f7d51a8 commit d8eb0f8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/org/java_websocket/client/WebSocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ private void reset() {
"You cannot initialize a reconnect out of the websocket thread. Use reconnect in another thread to ensure a successful cleanup.");
}
try {
if (engine.getReadyState() == ReadyState.NOT_YET_CONNECTED) {
// 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
if (engine.getReadyState() == ReadyState.NOT_YET_CONNECTED && socket != null) {
// Closing the socket when we have not connected prevents the writeThread from hanging on a write indefinitely during connection teardown
socket.close();
}
closeBlocking();
Expand Down

0 comments on commit d8eb0f8

Please sign in to comment.