Skip to content

Commit a41001f

Browse files
committed
fix race detector
1 parent 4cc4eed commit a41001f

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

frankenphp.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"runtime"
3333
"strings"
3434
"sync"
35+
"sync/atomic"
3536
"syscall"
3637
"time"
3738
"unsafe"
@@ -66,7 +67,8 @@ var (
6667

6768
metrics Metrics = nullMetrics{}
6869

69-
maxWaitTime time.Duration
70+
// atomic: read by in-flight requests while a reload may rewrite it
71+
maxWaitTime atomic.Int64
7072
maxRequestsPerThread int
7173
)
7274

@@ -275,7 +277,7 @@ func Init(options ...Option) error {
275277
metrics = opt.metrics
276278
}
277279

278-
maxWaitTime = opt.maxWaitTime
280+
maxWaitTime.Store(int64(opt.maxWaitTime))
279281
maxRequestsPerThread = opt.maxRequests
280282

281283
if opt.maxIdleTime > 0 {

threadregular.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"runtime"
77
"sync"
88
"sync/atomic"
9+
"time"
910

1011
"github.com/dunglas/frankenphp/internal/state"
1112
)
@@ -169,7 +170,7 @@ func handleRequestWithRegularPHPThreads(ch contextHolder) error {
169170
return nil
170171
case scaleChan <- ch.frankenPHPContext:
171172
// the request has triggered scaling, continue to wait for a thread
172-
case <-timeoutChan(maxWaitTime):
173+
case <-timeoutChan(time.Duration(maxWaitTime.Load())):
173174
// the request has timed out stalling
174175
queuedRegularThreads.Add(-1)
175176
metrics.DequeuedRequest()

0 commit comments

Comments
 (0)