Skip to content

fix: release state set between worker requests - #2830

Open
dunglas wants to merge 1 commit into
mainfrom
fix/worker-header-callback-leak
Open

dunglas wants to merge 1 commit into
mainfrom
fix/worker-header-callback-leak

Conversation

@dunglas

@dunglas dunglas commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Code running between two worker requests, in the worker loop or in a destructor, can set request state after the previous request reset it. Calling request functions there isn't supported, but nothing stopped it:

Called between requests Result
header_register_callback() sapi_activate() drops the callback without releasing it: it leaks with everything it captures until the worker stops
header(), setcookie(), a session cookie the headers list leaks
header('HTTP/1.1 ...') the status line leaks
header('Content-Type: ...') the mimetype leaks
fopen('php://input') the temporary body stream it creates leaks
output_add_rewrite_var() the URL rewriter stays active, so the next client's rewrite vars are never applied
session_id(), session_start() the next client gets that session instead of the one from their cookie

The session case is the one that matters: a destructor that touches the session between two requests hands it to the next client.

frankenphp_handle_request() now releases this state with the superglobals, before waiting for the next request. It skips the first call, where the worker script's boot request is still active.

The header callback leak was found while reading Rapira, which works around it.

Code running between two worker requests, in the worker loop or in a
destructor, can set request state after the previous request reset it.
sapi_activate() then drops the header callback, headers, status line,
mimetype and php://input body without releasing them, and the next
client inherits the URL rewriter state and the session.

Release this state before waiting for the next request.
@dunglas
dunglas force-pushed the fix/worker-header-callback-leak branch from a47cecd to 8f14144 Compare November 10, 2026 16:10
@dunglas dunglas changed the title fix: release header callback between requests fix: release state set between worker requests Nov 10, 2026

This branch has not been deployed

No deployments
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.

1 participant