Skip to content

Commit

Permalink
[UNDERTOW-2330] At HttpReadListener, handle race when connection is s…
Browse files Browse the repository at this point in the history
…hutdown concurrently with buffer allocation

Signed-off-by: Flavia Rainone <[email protected]>
  • Loading branch information
fl4via committed Oct 23, 2023
1 parent 88553c2 commit 1194286
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,21 @@ public void handleEvent(final ConduitStreamSourceChannel channel) {
public void handleEventWithNoRunningRequest(final ConduitStreamSourceChannel channel) {
PooledByteBuffer existing = connection.getExtraBytes();
if ((existing == null && connection.getOriginalSourceConduit().isReadShutdown()) || connection.getOriginalSinkConduit().isWriteShutdown()) {
UndertowLogger.REQUEST_IO_LOGGER.debug("Connection is closing, cancelling handling of request");
IoUtils.safeClose(connection);
channel.suspendReads();
return;
}
final PooledByteBuffer pooled;
try {
pooled = existing == null ? connection.getByteBufferPool().allocate() : existing;
} catch (IllegalStateException e) {
UndertowLogger.REQUEST_IO_LOGGER.debug("Connection is closing, cancelling handling of request", e);
// shutdown started after previous if statement, so treat it like previous statement
IoUtils.safeClose(connection);
channel.suspendReads();
return;
}

final PooledByteBuffer pooled = existing == null ? connection.getByteBufferPool().allocate() : existing;
final ByteBuffer buffer = pooled.getBuffer();
boolean free = true;

Expand Down

0 comments on commit 1194286

Please sign in to comment.