Skip to content

Commit 89552f7

Browse files
fix: thread restart
1 parent a4596b7 commit 89552f7

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

phpthread.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ func (thread *phpThread) shutdown() {
7979
}
8080
}
8181

82+
// restart the underlying PHP thread
83+
func (thread *phpThread) restart() {
84+
if !thread.state.requestSafeStateChange(stateRestarting) {
85+
return
86+
}
87+
close(thread.drainChan)
88+
thread.state.waitFor(stateYielding)
89+
thread.drainChan = make(chan struct{})
90+
91+
thread.state.waitFor(stateYielding)
92+
}
93+
8294
// change the thread handler safely
8395
// must be called from outside the PHP thread
8496
func (thread *phpThread) setHandler(handler threadHandler) {

worker.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,8 @@ func drainWorkerThreads() []*phpThread {
148148
worker.threadMutex.RLock()
149149
ready.Add(len(worker.threads))
150150
for _, thread := range worker.threads {
151-
if !thread.state.requestSafeStateChange(stateRestarting) {
152-
ready.Done()
153-
// no state change allowed == thread is shutting down
154-
// we'll proceed to restart all other threads anyways
155-
continue
156-
}
157-
close(thread.drainChan)
158-
drainedThreads = append(drainedThreads, thread)
159151
go func(thread *phpThread) {
160-
thread.state.waitFor(stateYielding)
152+
thread.restart()
161153
ready.Done()
162154
}(thread)
163155
}

0 commit comments

Comments
 (0)