You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2025/06/18 07:49:00 UTC
(tomcat) branch main updated: Correctly calculate h2 request statistics now requests are reused
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 4dc1a0f94b Correctly calculate h2 request statistics now requests are reused
4dc1a0f94b is described below
commit 4dc1a0f94bf17221a24a5f349771b9b36fd6d34d
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jun 18 08:48:46 2025 +0100
Correctly calculate h2 request statistics now requests are reused
---
java/org/apache/coyote/RequestInfo.java | 14 ++++++++++++++
java/org/apache/coyote/http2/StreamProcessor.java | 14 +++++++++++++-
webapps/docs/changelog.xml | 5 +++++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/coyote/RequestInfo.java b/java/org/apache/coyote/RequestInfo.java
index 41081f5806..0dc534da74 100644
--- a/java/org/apache/coyote/RequestInfo.java
+++ b/java/org/apache/coyote/RequestInfo.java
@@ -261,4 +261,18 @@ public class RequestInfo {
public void setLastRequestProcessingTime(long lastRequestProcessingTime) {
this.lastRequestProcessingTime = lastRequestProcessingTime;
}
+
+ public void recycleStatistcs() {
+ this.bytesSent = 0;
+ this.bytesReceived = 0;
+
+ this.processingTime = 0;
+ this.maxTime = 0;
+ this.maxRequestUri = null;
+
+ this.requestCount = 0;
+ this.errorCount = 0;
+
+ this.lastRequestProcessingTime = 0;
+ }
}
diff --git a/java/org/apache/coyote/http2/StreamProcessor.java b/java/org/apache/coyote/http2/StreamProcessor.java
index 2b7ea79701..edd9c74a9b 100644
--- a/java/org/apache/coyote/http2/StreamProcessor.java
+++ b/java/org/apache/coyote/http2/StreamProcessor.java
@@ -147,8 +147,14 @@ class StreamProcessor extends AbstractProcessor implements NonPipeliningProcesso
state = SocketState.CLOSED;
} finally {
if (state == SocketState.CLOSED) {
- stream.recycle();
+ /*
+ * Recycle this processor before the stream is recycled as recycling the stream will add the
+ * request and the response to the pool for re-use (if re-use is enabled) and the request
+ * statistics updating in StreamProcessor.recycle() needs to happen before the request and
+ * response are added to the pool to avoid concurrency issues corrupting the statistics.
+ */
recycle();
+ stream.recycle();
}
}
} finally {
@@ -416,6 +422,12 @@ class StreamProcessor extends AbstractProcessor implements NonPipeliningProcesso
global.removeRequestProcessor(request.getRequestProcessor());
}
+ /*
+ * Clear the statistics ready for re-use of the request. If we don't clear the statistics, the statistics for
+ * the current request will be included in the statistics for all future requests.
+ */
+ request.getRequestProcessor().recycleStatistcs();
+
// Clear fields that can be cleared to aid GC and trigger NPEs if this
// is reused
setSocketWrapper(null);
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index d1a10217cc..cadf1f7adb 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -197,6 +197,11 @@
<bug>69713</bug>: Correctly handle an HTTP/2 data frame that includes
padding when the headers include a content-length. (remm/markt)
</fix>
+ <fix>
+ Correctly collect statistics for HTTP/2 requests and avoid counting one
+ request multiple times. Based on pull request <pr>868</pr> by
+ qingdaoheze. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org