Skip to content

Commit c139708

Browse files
authored
Merge pull request #1528 from fl4via/UNDERTOW-2330
[UNDERTOW-2330] At HttpReadListener, handle race when connection is s…
2 parents 88553c2 + 1194286 commit c139708

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

core/src/main/java/io/undertow/server/protocol/http/HttpReadListener.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,21 @@ public void handleEvent(final ConduitStreamSourceChannel channel) {
139139
public void handleEventWithNoRunningRequest(final ConduitStreamSourceChannel channel) {
140140
PooledByteBuffer existing = connection.getExtraBytes();
141141
if ((existing == null && connection.getOriginalSourceConduit().isReadShutdown()) || connection.getOriginalSinkConduit().isWriteShutdown()) {
142+
UndertowLogger.REQUEST_IO_LOGGER.debug("Connection is closing, cancelling handling of request");
143+
IoUtils.safeClose(connection);
144+
channel.suspendReads();
145+
return;
146+
}
147+
final PooledByteBuffer pooled;
148+
try {
149+
pooled = existing == null ? connection.getByteBufferPool().allocate() : existing;
150+
} catch (IllegalStateException e) {
151+
UndertowLogger.REQUEST_IO_LOGGER.debug("Connection is closing, cancelling handling of request", e);
152+
// shutdown started after previous if statement, so treat it like previous statement
142153
IoUtils.safeClose(connection);
143154
channel.suspendReads();
144155
return;
145156
}
146-
147-
final PooledByteBuffer pooled = existing == null ? connection.getByteBufferPool().allocate() : existing;
148157
final ByteBuffer buffer = pooled.getBuffer();
149158
boolean free = true;
150159

0 commit comments

Comments
 (0)