Skip to content

Commit ed3edee

Browse files
committed
[grid] shutdown the client related to a websocket
1 parent b3db1d6 commit ed3edee

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

java/src/org/openqa/selenium/grid/node/ProxyNodeWebsockets.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,20 @@ private Consumer<Message> createWsEndPoint(
230230
client.openSocket(
231231
new HttpRequest(GET, uri.toString()),
232232
new ForwardingListener(downstream, sessionConsumer, sessionId));
233-
return upstream::send;
233+
234+
return (msg) -> {
235+
try {
236+
upstream.send(msg);
237+
} finally {
238+
if (msg instanceof CloseMessage) {
239+
try {
240+
client.close();
241+
} catch (Exception e) {
242+
LOG.log(Level.WARNING, "Failed to shutdown the client of " + uri, e);
243+
}
244+
}
245+
}
246+
};
234247
}
235248

236249
private static class ForwardingListener implements WebSocket.Listener {

java/src/org/openqa/selenium/grid/router/ProxyWebsocketsIntoGrid.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,20 @@ public Optional<Consumer<Message>> apply(String uri, Consumer<Message> downstrea
7171
WebSocket upstream =
7272
client.openSocket(new HttpRequest(GET, uri), new ForwardingListener(downstream));
7373

74-
return Optional.of(upstream::send);
74+
return Optional.of(
75+
(msg) -> {
76+
try {
77+
upstream.send(msg);
78+
} finally {
79+
if (msg instanceof CloseMessage) {
80+
try {
81+
client.close();
82+
} catch (Exception e) {
83+
LOG.log(Level.WARNING, "Failed to shutdown the client of " + sessionUri, e);
84+
}
85+
}
86+
}
87+
});
7588

7689
} catch (NoSuchSessionException e) {
7790
LOG.warning("Attempt to connect to non-existent session: " + uri);

0 commit comments

Comments
 (0)