From a472319905020c701ba48ebadacc8efbea7fb4b9 Mon Sep 17 00:00:00 2001 From: Artur Melanchyk <13834276+arturmelanchyk@users.noreply.github.com> Date: Wed, 8 Oct 2025 09:58:14 +0200 Subject: [PATCH] fix: thread restart --- phpthread.go | 10 ++++++++++ worker.go | 10 +--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/phpthread.go b/phpthread.go index a60aa8f0aa..010da91ab5 100644 --- a/phpthread.go +++ b/phpthread.go @@ -79,6 +79,16 @@ func (thread *phpThread) shutdown() { } } +// restart the underlying PHP thread +func (thread *phpThread) restart() { + if !thread.state.requestSafeStateChange(stateRestarting) { + return + } + close(thread.drainChan) + thread.state.waitFor(stateYielding) + thread.drainChan = make(chan struct{}) +} + // change the thread handler safely // must be called from outside the PHP thread func (thread *phpThread) setHandler(handler threadHandler) { diff --git a/worker.go b/worker.go index f28fb3ad6d..cffb9840a8 100644 --- a/worker.go +++ b/worker.go @@ -148,16 +148,8 @@ func drainWorkerThreads() []*phpThread { worker.threadMutex.RLock() ready.Add(len(worker.threads)) for _, thread := range worker.threads { - if !thread.state.requestSafeStateChange(stateRestarting) { - ready.Done() - // no state change allowed == thread is shutting down - // we'll proceed to restart all other threads anyways - continue - } - close(thread.drainChan) - drainedThreads = append(drainedThreads, thread) go func(thread *phpThread) { - thread.state.waitFor(stateYielding) + thread.restart() ready.Done() }(thread) }