From ecad5ec0a0af3ba122040ffd6b29c9b28230d476 Mon Sep 17 00:00:00 2001 From: Alexander Stecher <45872305+AlliBalliBaba@users.noreply.github.com> Date: Sat, 10 Jan 2026 21:40:54 +0100 Subject: [PATCH] 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. --- phpmainthread.go | 3 +++ phpmainthread_test.go | 2 +- watcher.go | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/phpmainthread.go b/phpmainthread.go index cecadc16..e10ce9e4 100644 --- a/phpmainthread.go +++ b/phpmainthread.go @@ -79,6 +79,9 @@ func initPHPThreads(numThreads int, numMaxThreads int, phpIni map[string]string) } func drainPHPThreads() { + if mainThread == nil { + return // mainThread was never initialized + } doneWG := sync.WaitGroup{} doneWG.Add(len(phpThreads)) mainThread.state.Set(state.ShuttingDown) diff --git a/phpmainthread_test.go b/phpmainthread_test.go index 7e6bf32c..b54647ae 100644 --- a/phpmainthread_test.go +++ b/phpmainthread_test.go @@ -96,7 +96,7 @@ func TestTransitionThreadsWhileDoingRequests(t *testing.T) { var ( isDone atomic.Bool - wg sync.WaitGroup + wg sync.WaitGroup ) numThreads := 10 diff --git a/watcher.go b/watcher.go index eb2b09e2..cfe133e5 100644 --- a/watcher.go +++ b/watcher.go @@ -10,7 +10,7 @@ import ( ) type hotReloadOpt struct { - hotReload []*watcher.PatternGroup + hotReload []*watcher.PatternGroup } var restartWorkers atomic.Bool