Fix persistent stream context lifetime during shutdown - #23853
Open
morrisonlevi wants to merge 2 commits into
Open
morrisonlevi wants to merge 2 commits into
morrisonlevi wants to merge 2 commits into
Conversation
morrisonlevi
marked this pull request as ready for review
September 22, 2026 23:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This problem sounds like something only a fuzzer or AI would find, but actually it's from a customer crash.
The reproducer creates a persistent stream during rshutdown and crashes during mshutdown when freeing streams, specifically when trying to access the stream context. The stream context was created in rshutdown and uses request-scoped memory, which is why it's a bad access in mshutdown.
I fix it in this patch by adding a check in
php_stream_context_freewhich loop over all the resources inEG(persistent_list)and removes the context from any streams which still use the context we're freeing. We do this only if the executor is in shutdown e.g.EG(flags) & EG_FLAGS_IN_RESOURCE_SHUTDOWN, so we're not doing this during a request, only at the end of a request. Doing it only in shutdown should mitigate performance concerns.This is my best attempt at fixing it as someone who knows little about streams. Maybe someone who knows more can find a better patch, as hopefully the reproducer is reliable across machines too.
Targeting PHP 8.4.