Skip to content

Commit 1ea3134

Browse files
committed
[java] Handling case where -1 is returned as statusCode
Closes #11910
1 parent 98d3e26 commit 1ea3134

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,17 @@ public WebSocket send(Message message) {
216216
LOG.fine("Sending text message: " + textMessage.text());
217217
makeCall = () -> underlyingSocket.sendText(textMessage.text(), true);
218218
} else if (message instanceof CloseMessage) {
219-
LOG.fine("Sending close message");
220219
CloseMessage closeMessage = (CloseMessage) message;
221-
makeCall = () -> underlyingSocket.sendClose(closeMessage.code(), closeMessage.reason());
220+
if (!underlyingSocket.isOutputClosed()) {
221+
// Sometimes the statusCode is -1, which could mean the socket is already closed.
222+
// We send a normal closure code in that case, though
223+
int statusCode = closeMessage.code() == -1 ? 1000 : closeMessage.code();
224+
LOG.fine(() -> String.format("Sending close message, statusCode %s, reason: %s", statusCode, closeMessage.reason()));
225+
makeCall = () -> underlyingSocket.sendClose(statusCode, closeMessage.reason());
226+
} else {
227+
LOG.fine("Output is closed, not sending close message");
228+
return this;
229+
}
222230
} else {
223231
throw new IllegalArgumentException("Unsupported message type: " + message);
224232
}

0 commit comments

Comments
 (0)