Copilot commented on code in PR #13232:
URL: https://github.com/apache/apisix/pull/13232#discussion_r3114682665


##########
apisix/tracer.lua:
##########
@@ -77,10 +77,13 @@ function _M.release(ctx)
         return
     end
 
-    for _, sp in ipairs(tracing.spans) do
-        sp:release()
+    local spans = tracing.spans
+    if spans then
+        for _, sp in ipairs(spans) do
+            sp:release()
+        end
+        tablepool.release("tracing_spans", spans)
     end
-    tablepool.release("tracing_spans", tracing.spans)
     tablepool.release("tracing", tracing)

Review Comment:
   After releasing `tracing` back to `lua-tablepool`, `ctx.tracing` is still 
left pointing at a table that may be immediately reused by another request. 
This can cause cross-request trace contamination (or double-release if 
`release()` is called again) because the stale reference remains truthy and may 
later contain unrelated data if the pool hands the table out again. Please 
clear the request context reference (e.g., set `ctx.tracing = nil`) once the 
pool releases have completed.
   ```suggestion
       tablepool.release("tracing", tracing)
       ctx.tracing = nil
   ```



-- 
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