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

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


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

commit 7f252d0c5a938d726f8eb757370c3f9c54937a54
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 161bc34e16..4b77434bdb 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -128,6 +128,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