Skip to content

Commit a10fa79

Browse files
joerg1985diemol
andauthored
ensure the correct output stream is used (#11175)
Prevent the random 'Unable to parse:' exception by fixing a race condition while transferring the data of a request. Co-authored-by: Diego Molina <[email protected]>
1 parent f5e195d commit a10fa79

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ protected void channelRead0(
110110

111111
if (msg instanceof HttpContent) {
112112
ByteBuf buf = ((HttpContent) msg).content().retain();
113+
PipedOutputStream target = out;
114+
113115
EXECUTOR.submit(() -> {
114116
try (InputStream inputStream = new ByteBufInputStream(buf)) {
115-
ByteStreams.copy(inputStream, out);
117+
ByteStreams.copy(inputStream, target);
116118
} catch (IOException e) {
117119
throw new UncheckedIOException(e);
118120
} finally {
@@ -123,9 +125,11 @@ protected void channelRead0(
123125

124126
if (msg instanceof LastHttpContent) {
125127
LOG.fine("Closing input pipe.");
128+
PipedOutputStream target = out;
129+
126130
EXECUTOR.submit(() -> {
127131
try {
128-
out.close();
132+
target.close();
129133
} catch (IOException e) {
130134
throw new UncheckedIOException(e);
131135
}
@@ -136,9 +140,11 @@ protected void channelRead0(
136140
@Override
137141
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
138142
LOG.fine("Closing input pipe, channel became inactive.");
143+
PipedOutputStream target = out;
144+
139145
SHUTDOWN_EXECUTOR.submit(() -> {
140146
try {
141-
out.close();
147+
target.close();
142148
} catch (IOException e) {
143149
throw new UncheckedIOException(e);
144150
}

0 commit comments

Comments
 (0)