This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new ec32fee38b Correctly calculate h2 request statistics now requests are 
reused
ec32fee38b is described below

commit ec32fee38b4924391aec0c5af3f7c44e71a26ed0
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 55b913e63a..b8fb78469d 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 {
@@ -433,6 +439,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 a3214cd2e4..35a24f4775 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -124,6 +124,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="Web applications">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to