diff --git a/phpthread.go b/phpthread.go index a60aa8f0a..010da91ab 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 f28fb3ad6..cffb9840a 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) }