Skip to content

Conversation

@tzssangglass
Copy link
Contributor

@tzssangglass tzssangglass commented Nov 4, 2025

When a client disconnects during an HTTP/2 subrequest (e.g., while ngx.sleep() is yielding), the subrequest fails to wake up its parent request, causing the parent's Lua coroutine to hang indefinitely.

Root cause: HTTP/2 sets c->error=1 immediately on client disconnect, triggering the error path in ngx_http_finalize_request(). This path calls ngx_http_terminate_request(), which clears the posted_requests queue before the parent can be processed.

Solution: In ngx_http_finalize_request(), when a subrequest completes with c->error set, manually update subrequest state and wake the parent request, then return immediately to avoid ngx_http_terminate_request().

This fix ensures the parent request can process the subrequest response even when the client connection is closed, which is critical for OpenResty's async subrequest mechanism with ngx.location.capture().

fix: #1076

I hereby granted the copyright of the changes in this pull request
to the authors of this openresty project.

@tzssangglass tzssangglass changed the title fix: wake parent request when HTTP/2 subrequest finishes with error bugfix: wake parent request when HTTP/2 subrequest finishes with error Nov 4, 2025
@tzssangglass
Copy link
Contributor Author

hi @zhuizhuhaomeng can you pls tell me where to add this patch before the CI build openresty bin

@zhuizhuhaomeng
Copy link
Contributor

please see file ./util/mirror-tarballs

@tzssangglass tzssangglass force-pushed the http2_subreq_error_wakeup branch from cb64fbc to b168a0d Compare November 4, 2025 14:22
When a client disconnects during an HTTP/2 subrequest (e.g., while
ngx.sleep() is yielding), the subrequest fails to wake up its parent
request, causing the parent's Lua coroutine to hang indefinitely.

Root cause: HTTP/2 sets c->error=1 immediately on client disconnect,
triggering the error path in ngx_http_finalize_request(). This path
calls ngx_http_terminate_request(), which clears the posted_requests
queue before the parent can be processed.

Solution: In ngx_http_finalize_request(), when a subrequest completes
with c->error set, manually update subrequest state and wake the parent
request, then return immediately to avoid ngx_http_terminate_request().

This fix ensures the parent request can process the subrequest response
even when the client connection is closed, which is critical for
OpenResty's async subrequest mechanism with ngx.location.capture().

Signed-off-by: tzssangglass <tzssangglass@gmail.com>
@tzssangglass tzssangglass force-pushed the http2_subreq_error_wakeup branch from b168a0d to 18c077b Compare November 4, 2025 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Record empty status code

2 participants