[php-src] PR #23853: Fix persistent stream context lifetime during shutdown

From: Date: Tue, 22 Sep 2026 20:55:09 +0000
Subject: [php-src] PR #23853: Fix persistent stream context lifetime during shutdown
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-38728@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/23853 Author: morrisonlevi 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_free which loop over all the resources in EG(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.

« previous php.git-pulls (#38728) next »