Skip to content

Commit 401a7ae

Browse files
committed
docs: clarify ngx.sleep(0) is a workaround, link tracking issue #13256
Per review feedback, the comment now states explicitly that the yield prevents one request from monopolizing the worker but does not bound per-stream CPU time, add backpressure, or time out stalled streams. A real fix is tracked in #13256.
1 parent 1008af0 commit 401a7ae

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

apisix/plugins/ai-providers/base.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,15 @@ function _M.parse_streaming_response(self, ctx, res, target_proto, converter)
362362
plugin.lua_response_filter(ctx, res.headers, chunk)
363363
end
364364

365-
-- Yield to the nginx scheduler so other coroutines on this worker
366-
-- (health checks, concurrent requests) can run. body_reader() and
367-
-- ngx.flush() do not yield when the upstream socket already has data
368-
-- buffered or the downstream client drains immediately, so under
369-
-- bursty SSE upstreams this loop can monopolize the worker CPU.
365+
-- WORKAROUND, not a real fix: yield to the nginx scheduler so other
366+
-- coroutines on this worker (health checks, concurrent requests) can
367+
-- run. body_reader() and ngx.flush() do not yield when the upstream
368+
-- socket already has data buffered or the downstream client drains
369+
-- immediately, so under bursty SSE upstreams this loop can monopolize
370+
-- the worker CPU. ngx.sleep(0) only prevents a single request from
371+
-- monopolizing the worker; it does not bound per-stream CPU time, add
372+
-- backpressure, or time out stalled streams. See #13256 for a proper
373+
-- solution.
370374
ngx.sleep(0)
371375
end
372376
end

0 commit comments

Comments
 (0)