Skip to content

Commit db3e1a0

Browse files
fix: race condition revealed by tests (#1403)
* Resolves a race condition * Removes unused code. * trigger build * Removes accidental files. --------- Co-authored-by: Alliballibaba <alliballibaba@gmail.com>
1 parent 80f13f0 commit db3e1a0

2 files changed

Lines changed: 3 additions & 26 deletions

File tree

scaling.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,6 @@ func addRegularThread() (*phpThread, error) {
7474
return thread, nil
7575
}
7676

77-
func removeRegularThread() error {
78-
regularThreadMu.RLock()
79-
if len(regularThreads) <= 1 {
80-
regularThreadMu.RUnlock()
81-
return CannotRemoveLastThreadError
82-
}
83-
thread := regularThreads[len(regularThreads)-1]
84-
regularThreadMu.RUnlock()
85-
thread.shutdown()
86-
return nil
87-
}
88-
8977
func addWorkerThread(worker *worker) (*phpThread, error) {
9078
thread := getInactivePHPThread()
9179
if thread == nil {
@@ -96,19 +84,6 @@ func addWorkerThread(worker *worker) (*phpThread, error) {
9684
return thread, nil
9785
}
9886

99-
func removeWorkerThread(worker *worker) error {
100-
worker.threadMutex.RLock()
101-
if len(worker.threads) <= 1 {
102-
worker.threadMutex.RUnlock()
103-
return CannotRemoveLastThreadError
104-
}
105-
thread := worker.threads[len(worker.threads)-1]
106-
worker.threadMutex.RUnlock()
107-
thread.shutdown()
108-
109-
return nil
110-
}
111-
11287
// scaleWorkerThread adds a worker PHP thread automatically
11388
func scaleWorkerThread(worker *worker) {
11489
scalingMu.Lock()

threadworker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,10 @@ func (handler *workerThread) waitForWorkerRequest() bool {
150150
c.Write(zap.String("worker", handler.worker.fileName))
151151
}
152152

153-
if handler.state.compareAndSwap(stateTransitionComplete, stateReady) {
153+
// worker threads are 'ready' only after they first reach frankenphp_handle_request()
154+
if handler.state.is(stateTransitionComplete) {
154155
metrics.ReadyWorker(handler.worker.fileName)
156+
handler.state.set(stateReady)
155157
}
156158

157159
handler.state.markAsWaiting(true)

0 commit comments

Comments
 (0)