From 38d8243dd9c67d35adf48f7467cefcd262ce9ea0 Mon Sep 17 00:00:00 2001 From: baranowb Date: Thu, 10 Jul 2025 12:24:21 +0200 Subject: [PATCH] [UNDERTOW-2575] Add flush before socket close on write timeout --- .../undertow/conduits/WriteTimeoutStreamSinkConduit.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/main/java/io/undertow/conduits/WriteTimeoutStreamSinkConduit.java b/core/src/main/java/io/undertow/conduits/WriteTimeoutStreamSinkConduit.java index 8398c8b43c..5971041dd4 100644 --- a/core/src/main/java/io/undertow/conduits/WriteTimeoutStreamSinkConduit.java +++ b/core/src/main/java/io/undertow/conduits/WriteTimeoutStreamSinkConduit.java @@ -109,7 +109,15 @@ private void handleWriteTimeout(final long ret) throws IOException { long expireTimeVar = expireTime; if (expireTimeVar != -1 && currentTime > expireTimeVar) { this.expireTime = -1; + //shutdown write will call AbstractFramedStreamSinkConduit#queueCloseFrames. In some cases it will schedule + //additional packets to adhere to protocol, we need to flush content( this would happen later, if not for + //subsequent close connection.getSinkChannel().shutdownWrites(); + try { + connection.getSinkChannel().flush(); + } catch(IOException e) { + UndertowLogger.REQUEST_LOGGER.ioException(e); + } IoUtils.safeClose(connection); throw new ClosedChannelException(); }