nic-6443 commented on code in PR #13224:
URL: https://github.com/apache/apisix/pull/13224#discussion_r3085227124


##########
apisix/core/response.lua:
##########
@@ -195,33 +194,33 @@ function _M.get_response_source(ctx)
         return ctx._resp_source
     end
 
-    -- Priority 2: request was proxied — inspect the last 
$upstream_header_time token
+    -- Priority 2: request was proxied — inspect $upstream_bytes_received
+    -- to determine if the upstream actually sent a response.
     if ctx._apisix_proxied then
-        -- Use pcall to safely access upstream_header_time via ctx.var, which 
may
-        -- error in certain NGINX error paths (e.g. connection refused).
-        local header_time
+        -- $upstream_bytes_received: number of bytes received from upstream.

Review Comment:
   Thanks for the thorough NGINX source analysis! Totally agree — 
`$upstream_header_time` is the right signal here.
   
   The previous commit was using `ctx.var.upstream_bytes_received` as a 
workaround because `ctx.var.upstream_header_time` goes through 
`lua-var-nginx-module`'s FFI which clamps `header_time` from `-1` to `0` via 
`ngx_max(ms, 0)` in `ngx_http_lua_var_ffi_upstream_response_time()`, making 
connection refused indistinguishable from fast upstream responses.
   
   The latest commit (9c84b01) switches to `ngx.var.upstream_header_time` which 
bypasses the FFI path and preserves the "-" sentinel. Should be exactly aligned 
with your analysis now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to