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

nickva pushed a commit to branch fix-stale-body-time
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 0f364fd7a4b4fc884f299ca53de059e19ccd00f9
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Thu Nov 5 15:23:10 2026 -0500

    Reset body_time between requests
    
    Mochiweb and our request handler may reuse the request process and we don't
    want to send back a stale `x-couchdb-body-time` in that case (with a 
subsequent
    GET request or something). So always reset it before starting a request.
---
 src/chttpd/src/chttpd.erl | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index 80f15005c..43b569305 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -230,8 +230,6 @@ stop() ->
 
 handle_request(MochiReq0) ->
     erlang:put(?REWRITE_COUNT, 0),
-    % Mochiweb handles all requests on a keep-alive connection in the same
-    % process, so don't report the previous request's body time.
     erlang:erase(body_time),
     MochiReq = couch_httpd_vhost:dispatch_host(MochiReq0),
     handle_request_int(MochiReq).
@@ -770,8 +768,14 @@ body(#httpd{mochi_req = MochiReq, req_body = ReqBody}) ->
             try
                 MochiReq:recv_body(MaxSize)
             after
-                T = timer:now_diff(os:timestamp(), Begin) div 1000,
-                put(body_time, T)
+                case get(body_time) of
+                    undefined ->
+                        T = timer:now_diff(os:timestamp(), Begin) div 1000,
+                        put(body_time, T);
+                    _ ->
+                        % Already read once and set it
+                        ok
+                end
             end;
         _Else ->
             ReqBody

Reply via email to