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 6b16144a448dab17634db6bc6ff509e508c7bbf6
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Thu Nov 5 15:20:29 2026 -0500

    Make sure to reset body_time after handling each request
    
    Otherwise if keep-alive the connection we might not clear this and get 
wrong value
    returned with the next request
---
 src/chttpd/src/chttpd.erl | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index 645083591..43b569305 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -230,6 +230,7 @@ stop() ->
 
 handle_request(MochiReq0) ->
     erlang:put(?REWRITE_COUNT, 0),
+    erlang:erase(body_time),
     MochiReq = couch_httpd_vhost:dispatch_host(MochiReq0),
     handle_request_int(MochiReq).
 
@@ -767,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