From 82d6696c9d152c0e5c52a56ebb159ad9bbc8a870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 11 Feb 2026 15:18:55 +0100 Subject: [PATCH] fix: race condition in thread shutdown during drain --- phpthread.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpthread.go b/phpthread.go index 40d04eff..5ff15b64 100644 --- a/phpthread.go +++ b/phpthread.go @@ -66,9 +66,11 @@ func (thread *phpThread) boot() { // shutdown the underlying PHP thread func (thread *phpThread) shutdown() { if !thread.state.RequestSafeStateChange(state.ShuttingDown) { - // already shutting down or done + // already shutting down or done, wait for the C thread to finish + thread.state.WaitFor(state.Done, state.Reserved) return } + close(thread.drainChan) thread.state.WaitFor(state.Done) thread.drainChan = make(chan struct{})