fix: properly cleanup workersReadyWG (#184)

This commit is contained in:
Kévin Dunglas 2023-08-12 12:39:13 +02:00 committed by GitHub
parent b03ce0eb20
commit 307c5fa865
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -282,11 +282,8 @@ func Init(options ...Option) error {
return MainThreadCreationError
}
for _, w := range opt.workers {
// TODO: start all the worker in parallell to reduce the boot time
if err := startWorkers(w.fileName, w.num); err != nil {
return err
}
if err := initWorkers(opt.workers); err != nil {
return err
}
logger.Debug("FrankenPHP started")
@ -301,6 +298,9 @@ func Shutdown() {
shutdownWG.Wait()
requestChan = nil
// Always reset the WaitGroup to ensure we're in a clean state
workersReadyWG = sync.WaitGroup{}
logger.Debug("FrankenPHP shut down")
}

View File

@ -17,9 +17,19 @@ import (
var (
workersRequestChans sync.Map // map[fileName]chan *http.Request
workersReadyWG sync.WaitGroup
workersWG sync.WaitGroup
)
// TODO: start all the worker in parallell to reduce the boot time
func initWorkers(opt []workerOpt) error {
for _, w := range opt {
if err := startWorkers(w.fileName, w.num); err != nil {
return err
}
}
return nil
}
func startWorkers(fileName string, nbWorkers int) error {
absFileName, err := filepath.Abs(fileName)
if err != nil {
@ -35,7 +45,7 @@ func startWorkers(fileName string, nbWorkers int) error {
workersReadyWG.Add(nbWorkers)
var (
m sync.Mutex
m sync.RWMutex
errors []error
)