From 165af62eae9e45c8152f8e6d426b0637d6292bd6 Mon Sep 17 00:00:00 2001 From: Aaron Ogburn Date: Mon, 28 Jul 2025 15:59:51 -0400 Subject: [PATCH 1/2] [UNDERTOW-2588] avoid buffer clear that breaks NewSessionTicket writes --- .../undertow/server/protocol/http/HttpResponseConduit.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/undertow/server/protocol/http/HttpResponseConduit.java b/core/src/main/java/io/undertow/server/protocol/http/HttpResponseConduit.java index f8fdfe916c..43e30b489e 100644 --- a/core/src/main/java/io/undertow/server/protocol/http/HttpResponseConduit.java +++ b/core/src/main/java/io/undertow/server/protocol/http/HttpResponseConduit.java @@ -129,6 +129,7 @@ private int processWrite(int state, final Object userData, int pos, int length) if (done || exchange == null) { throw new ClosedChannelException(); } + boolean buffDone = true; ByteBuffer buffer = null; try { assert state != STATE_BODY; @@ -157,6 +158,7 @@ private int processWrite(int state, final Object userData, int pos, int length) res = next.write(data, 0, length + 1); } if (res == 0) { + buffDone = false; return STATE_BUF_FLUSH; } } while (buffer.hasRemaining()); @@ -291,12 +293,13 @@ private int processWrite(int state, final Object userData, int pos, int length) res = next.write(data, 0, index + length); } if (res == 0) { + buffDone = false; return STATE_BUF_FLUSH; } } while (buffer != null && buffer.hasRemaining()); return STATE_BODY; } finally { - if (buffer != null) { + if (buffer != null && buffDone) { bufferDone(); this.state &= ~POOLED_BUFFER_IN_USE; } From 58f2f35248f8ffe62d3fcce8a8cf79e17cc06f86 Mon Sep 17 00:00:00 2001 From: Aaron Ogburn Date: Mon, 15 Sep 2025 10:30:01 -0400 Subject: [PATCH 2/2] [UNDERTOW-25898] add clarifying comments --- .../io/undertow/server/protocol/http/HttpResponseConduit.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/java/io/undertow/server/protocol/http/HttpResponseConduit.java b/core/src/main/java/io/undertow/server/protocol/http/HttpResponseConduit.java index 43e30b489e..f692f67533 100644 --- a/core/src/main/java/io/undertow/server/protocol/http/HttpResponseConduit.java +++ b/core/src/main/java/io/undertow/server/protocol/http/HttpResponseConduit.java @@ -158,6 +158,7 @@ private int processWrite(int state, final Object userData, int pos, int length) res = next.write(data, 0, length + 1); } if (res == 0) { + // UNDERTOW-2588 - skip bufferDone() for a STATE_BUF_FLUSH return buffDone = false; return STATE_BUF_FLUSH; } @@ -293,6 +294,7 @@ private int processWrite(int state, final Object userData, int pos, int length) res = next.write(data, 0, index + length); } if (res == 0) { + // UNDERTOW-2588 - skip bufferDone() for a STATE_BUF_FLUSH return buffDone = false; return STATE_BUF_FLUSH; } @@ -300,6 +302,7 @@ private int processWrite(int state, final Object userData, int pos, int length) return STATE_BODY; } finally { if (buffer != null && buffDone) { + // UNDERTOW-2588 - skip this for a STATE_BUF_FLUSH return bufferDone(); this.state &= ~POOLED_BUFFER_IN_USE; }