This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 3f60e3662a Refactor clean-up of header buffer. Align reset with
headers complete.
3f60e3662a is described below
commit 3f60e3662a9b7b3c7aff7988e6190096b3b22f07
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Apr 8 08:45:20 2026 +0100
Refactor clean-up of header buffer. Align reset with headers complete.
---
java/org/apache/coyote/http2/Http2Parser.java | 29 ++++++++++++++++-----------
webapps/docs/changelog.xml | 4 ++++
2 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/java/org/apache/coyote/http2/Http2Parser.java
b/java/org/apache/coyote/http2/Http2Parser.java
index 5cb340efe1..e6db6d6b02 100644
--- a/java/org/apache/coyote/http2/Http2Parser.java
+++ b/java/org/apache/coyote/http2/Http2Parser.java
@@ -304,14 +304,11 @@ class Http2Parser {
long errorCode = ByteUtil.getFourBytes(payload, 0);
output.reset(streamId, errorCode);
+
headersCurrentStream = -1;
- if (headerReadBuffer.capacity() >
Constants.DEFAULT_HEADER_READ_BUFFER_SIZE) {
- // Reset size for new request if the buffer was previously expanded
- headerReadBuffer =
ByteBuffer.allocate(Constants.DEFAULT_HEADER_READ_BUFFER_SIZE);
- } else {
- headerReadBuffer.clear();
- }
headersEndStream = false;
+ // Force clearing of header buffer as there may be data left over
+ afterHeadersCompleteCleanUp(true);
}
@@ -646,12 +643,6 @@ class Http2Parser {
Http2Error.COMPRESSION_ERROR);
}
- /*
- * Clear the reference to the stream in the HPack decoder now that the
headers have been processed so that the
- * HPack decoder does not retain a reference to this stream. This aids
GC.
- */
- hpackDecoder.clearHeaderEmitter();
-
synchronized (output) {
output.headersEnd(streamId, headersEndStream);
@@ -660,10 +651,24 @@ class Http2Parser {
}
}
+ // We know from test above that buffer is empty so no need to force it
to be cleared
+ afterHeadersCompleteCleanUp(false);
+ }
+
+
+ protected void afterHeadersCompleteCleanUp(boolean forceClear) {
// Reset size for new request if the buffer was previously expanded
if (headerReadBuffer.capacity() >
Constants.DEFAULT_HEADER_READ_BUFFER_SIZE) {
headerReadBuffer =
ByteBuffer.allocate(Constants.DEFAULT_HEADER_READ_BUFFER_SIZE);
+ } else if (forceClear) {
+ headerReadBuffer.clear();
}
+
+ /*
+ * Clear the reference to the stream in the HPack decoder now that the
headers have been processed so that the
+ * HPack decoder does not retain a reference to this stream. This aids
GC.
+ */
+ hpackDecoder.clearHeaderEmitter();
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 5ede03a547..db1864f04e 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -254,6 +254,10 @@
Fix a few minor memory leaks on error paths reading TLS keys and
certificates when using FFM. (markt)
</fix>
+ <fix>
+ Refactor clean-up after HTTP/2 headers have been processed to aid GC
+ after a stream reset. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]