Skip to content

Commit ecad5ec

Browse files
fix: prevent segfault on early shutdown. (#2120)
Fixes #2114 This early [Shutdown](https://github.com/php/frankenphp/blob/11160fb7b31171d706cf9933abb9102dbb1cdb3c/frankenphp.go#L281) introduced in #2031 segfaults instead of returning an error since threads have not started yet.
1 parent 11160fb commit ecad5ec

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

phpmainthread.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ func initPHPThreads(numThreads int, numMaxThreads int, phpIni map[string]string)
7979
}
8080

8181
func drainPHPThreads() {
82+
if mainThread == nil {
83+
return // mainThread was never initialized
84+
}
8285
doneWG := sync.WaitGroup{}
8386
doneWG.Add(len(phpThreads))
8487
mainThread.state.Set(state.ShuttingDown)

phpmainthread_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestTransitionThreadsWhileDoingRequests(t *testing.T) {
9696

9797
var (
9898
isDone atomic.Bool
99-
wg sync.WaitGroup
99+
wg sync.WaitGroup
100100
)
101101

102102
numThreads := 10

watcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
type hotReloadOpt struct {
13-
hotReload []*watcher.PatternGroup
13+
hotReload []*watcher.PatternGroup
1414
}
1515

1616
var restartWorkers atomic.Bool

0 commit comments

Comments
 (0)