From 6cf248033a77a152a14699d68b7f349d8203ca87 Mon Sep 17 00:00:00 2001 From: baranowb Date: Tue, 12 Nov 2024 13:19:41 +0100 Subject: [PATCH] [UNDERTOW-2356] PreChunkedStreamSinkConduit --- .../undertow/conduits/PreChunkedStreamSinkConduit.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/io/undertow/conduits/PreChunkedStreamSinkConduit.java b/core/src/main/java/io/undertow/conduits/PreChunkedStreamSinkConduit.java index 2255e6fdd4..942267836a 100644 --- a/core/src/main/java/io/undertow/conduits/PreChunkedStreamSinkConduit.java +++ b/core/src/main/java/io/undertow/conduits/PreChunkedStreamSinkConduit.java @@ -33,6 +33,7 @@ import java.nio.channels.ClosedChannelException; import java.nio.channels.FileChannel; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import static org.xnio.Bits.allAreClear; import static org.xnio.Bits.anyAreSet; @@ -52,7 +53,9 @@ public class PreChunkedStreamSinkConduit extends AbstractStreamSinkConduit stateUpdater = AtomicIntegerFieldUpdater.newUpdater( + PreChunkedStreamSinkConduit.class, "state"); final ChunkReader chunkReader; /** @@ -183,7 +186,7 @@ public boolean flush() throws IOException { } private void invokeFinishListener() { - state |= FLAG_FINISHED; + stateUpdater.accumulateAndGet(this, FLAG_FINISHED, (current, flag) -> current | flag); if (finishListener != null) { finishListener.handleEvent(this); } @@ -197,7 +200,7 @@ public void terminateWrites() throws IOException { if (chunkReader.getChunkRemaining() != -1) { throw UndertowMessages.MESSAGES.chunkedChannelClosedMidChunk(); } - state |= FLAG_WRITES_SHUTDOWN; + stateUpdater.accumulateAndGet(this, FLAG_WRITES_SHUTDOWN, (current, flag) -> current | flag); } @Override