From d4bbb1001539994d382bd6754f95e148e021f4da Mon Sep 17 00:00:00 2001 From: Alliballibaba Date: Thu, 13 Mar 2025 20:09:00 +0100 Subject: [PATCH 1/3] ensure $_ENV is not in an invalid state before shutdown --- frankenphp.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/frankenphp.c b/frankenphp.c index a20d40186d..ea6b14e349 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -405,10 +405,11 @@ PHP_FUNCTION(frankenphp_handle_request) { zend_unset_timeout(); #endif - bool has_request = go_frankenphp_worker_handle_request_start(thread_index); - if (frankenphp_worker_request_startup() == FAILURE - /* Shutting down */ - || !has_request) { + bool continue_handling_requests = + go_frankenphp_worker_handle_request_start(thread_index); + if (!continue_handling_requests || + frankenphp_worker_request_startup() == FAILURE) { + /* Shutting down */ RETURN_FALSE; } @@ -501,6 +502,11 @@ static zend_module_entry frankenphp_module = { STANDARD_MODULE_PROPERTIES}; static void frankenphp_request_shutdown() { + if (is_worker_thread) { + /* ensure $_ENV is not in an invalid state before shutdown */ + zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_ENV]); + array_init(&PG(http_globals)[TRACK_VARS_ENV]); + } php_request_shutdown((void *)0); frankenphp_free_request_context(); } From e1560e007d744f1f3950f8b97d0a0681b9826718 Mon Sep 17 00:00:00 2001 From: Alliballibaba Date: Thu, 13 Mar 2025 20:18:26 +0100 Subject: [PATCH 2/3] trigger From cde8095947ea0740303c5a796de707b9e9b52a94 Mon Sep 17 00:00:00 2001 From: Alliballibaba Date: Fri, 14 Mar 2025 00:07:19 +0100 Subject: [PATCH 3/3] Resets shutdown order. --- frankenphp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frankenphp.c b/frankenphp.c index ea6b14e349..f9be7a5a22 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -405,11 +405,10 @@ PHP_FUNCTION(frankenphp_handle_request) { zend_unset_timeout(); #endif - bool continue_handling_requests = - go_frankenphp_worker_handle_request_start(thread_index); - if (!continue_handling_requests || - frankenphp_worker_request_startup() == FAILURE) { - /* Shutting down */ + bool has_request = go_frankenphp_worker_handle_request_start(thread_index); + if (frankenphp_worker_request_startup() == FAILURE + /* Shutting down */ + || !has_request) { RETURN_FALSE; }