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

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


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 6909ac966b Refactor recording of request start time
6909ac966b is described below

commit 6909ac966bcafd21d1633ccde63428b8bf491a37
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Sep 22 16:55:02 2025 +0100

    Refactor recording of request start time
---
 java/org/apache/coyote/AbstractProcessor.java        |  6 +++---
 java/org/apache/coyote/Request.java                  | 12 ++++++++++++
 java/org/apache/coyote/ajp/AjpProcessor.java         |  2 +-
 java/org/apache/coyote/http11/Http11InputBuffer.java |  7 +++----
 java/org/apache/coyote/http2/Stream.java             |  4 +---
 5 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/java/org/apache/coyote/AbstractProcessor.java 
b/java/org/apache/coyote/AbstractProcessor.java
index 3b8164eb46..6cfb24ec83 100644
--- a/java/org/apache/coyote/AbstractProcessor.java
+++ b/java/org/apache/coyote/AbstractProcessor.java
@@ -1083,9 +1083,9 @@ public abstract class AbstractProcessor extends 
AbstractProcessorLight implement
         // Set the socket wrapper so the access log can read the socket related
         // information (e.g. client IP)
         setSocketWrapper(socketWrapper);
-        // Setup the minimal request information
-        request.setStartTime(System.currentTimeMillis());
-        // Setup the minimal response information
+        // Set up the minimal request information
+        request.markStartTime();
+        // Set up the minimal response information
         response.setStatus(400);
         response.setError();
         getAdapter().log(request, response, 0);
diff --git a/java/org/apache/coyote/Request.java 
b/java/org/apache/coyote/Request.java
index 7ed5ef4cd8..1808262e71 100644
--- a/java/org/apache/coyote/Request.java
+++ b/java/org/apache/coyote/Request.java
@@ -693,10 +693,22 @@ public final class Request {
         return startTime;
     }
 
+    /**
+     * Set the start time using the value provided by {@code 
System.currentTimeMillis()}.
+     *
+     * @param startTime The value returned from {@code 
System.currentTimeMillis()} at the point the requests started.
+     *
+     * @deprecated Unused. Will be removed in Tomcat 12 onwards. Use {@link 
#markStartTime()}.
+     */
+    @Deprecated
     public void setStartTime(long startTime) {
         this.startTime = startTime;
     }
 
+    public void markStartTime() {
+        startTime = System.currentTimeMillis();
+    }
+
     public long getThreadId() {
         return threadId;
     }
diff --git a/java/org/apache/coyote/ajp/AjpProcessor.java 
b/java/org/apache/coyote/ajp/AjpProcessor.java
index 5c129a13b5..7f5070f4c5 100644
--- a/java/org/apache/coyote/ajp/AjpProcessor.java
+++ b/java/org/apache/coyote/ajp/AjpProcessor.java
@@ -385,7 +385,7 @@ public class AjpProcessor extends AbstractProcessor {
                     setErrorState(ErrorState.CLOSE_CONNECTION_NOW, null);
                     break;
                 }
-                request.setStartTime(System.currentTimeMillis());
+                request.markStartTime();
             } catch (IOException ioe) {
                 setErrorState(ErrorState.CLOSE_CONNECTION_NOW, ioe);
                 break;
diff --git a/java/org/apache/coyote/http11/Http11InputBuffer.java 
b/java/org/apache/coyote/http11/Http11InputBuffer.java
index 9903301011..e0fb9cefcc 100644
--- a/java/org/apache/coyote/http11/Http11InputBuffer.java
+++ b/java/org/apache/coyote/http11/Http11InputBuffer.java
@@ -343,8 +343,6 @@ public class Http11InputBuffer implements InputBuffer, 
ApplicationBufferHandler
                         wrapper.setReadTimeout(keepAliveTimeout);
                     }
                     if (!fill(false)) {
-                        // A read is pending, so no longer in initial state
-                        parsingRequestLinePhase = 1;
                         return false;
                     }
                     // At least one byte of the request has been received.
@@ -366,8 +364,9 @@ public class Http11InputBuffer implements InputBuffer, 
ApplicationBufferHandler
                 }
                 // Set the start time once we start reading data (even if it is
                 // just skipping blank lines)
-                if (request.getStartTime() < 0) {
-                    request.setStartTime(System.currentTimeMillis());
+                if (parsingRequestLinePhase == 0) {
+                    parsingRequestLinePhase = 1;
+                    request.markStartTime();
                 }
                 chr = byteBuffer.get();
             } while (chr == Constants.CR || chr == Constants.LF);
diff --git a/java/org/apache/coyote/http2/Stream.java 
b/java/org/apache/coyote/http2/Stream.java
index ce7d9e50cd..94322c6fc6 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -166,9 +166,7 @@ class Stream extends AbstractNonZeroStream implements 
HeaderEmitter {
         this.coyoteResponse.setOutputBuffer(http2OutputBuffer);
         this.coyoteRequest.setResponse(coyoteResponse);
         this.coyoteRequest.protocol().setString("HTTP/2.0");
-        if (this.coyoteRequest.getStartTime() < 0) {
-            this.coyoteRequest.setStartTime(System.currentTimeMillis());
-        }
+        this.coyoteRequest.markStartTime();
     }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to