Skip to content

Commit 3ad99eb

Browse files
committed
[grid] Closing input pipeline when client disconnects
This is needed when a client sends a request, and we reply right away (e.g. session not found), but we do not read the whole request content. If we do not read the whole request content, Netty will wait until it does, and then it blocks. Which is not ideal since no more requests can be processed. Now, we close the pipeline when the client disconnects. Fixes #10485 Fixes SeleniumHQ/docker-selenium#1439
1 parent 439da14 commit 3ad99eb

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

‎java/src/org/openqa/selenium/events/zeromq/UnboundZmqEventBus.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ public void run() {
231231
EventName eventName = new EventName(new String(socket.recv(), UTF_8));
232232
// Processing only events we are listening to
233233
if (!listeners.containsKey(eventName)) {
234-
// LOG.log(Level.SEVERE, "Ignoring {0}", eventName);
235234
continue;
236235
}
237236

‎java/src/org/openqa/selenium/netty/server/RequestConverter.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class RequestConverter extends SimpleChannelInboundHandler<HttpObject> {
6161

6262
private static final Logger LOG = Logger.getLogger(RequestConverter.class.getName());
6363
private static final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor();
64+
private static final ExecutorService SHUTDOWN_EXECUTOR = Executors.newSingleThreadExecutor();
6465
private static final List<io.netty.handler.codec.http.HttpMethod> supportedMethods =
6566
Arrays.asList(DELETE, GET, POST, OPTIONS);
6667
private volatile PipedOutputStream out;
@@ -132,6 +133,19 @@ protected void channelRead0(
132133
}
133134
}
134135

136+
@Override
137+
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
138+
LOG.fine("Closing input pipe, channel became inactive.");
139+
SHUTDOWN_EXECUTOR.submit(() -> {
140+
try {
141+
out.close();
142+
} catch (IOException e) {
143+
throw new UncheckedIOException(e);
144+
}
145+
});
146+
super.channelInactive(ctx);
147+
}
148+
135149
private HttpRequest createRequest(
136150
ChannelHandlerContext ctx,
137151
io.netty.handler.codec.http.HttpRequest nettyRequest) {

0 commit comments

Comments
 (0)