mirror of
https://github.com/dunglas/frankenphp
synced 2024-10-16 17:14:59 +00:00
fix: properly cleanup workersReadyWG (#184)
This commit is contained in:
parent
b03ce0eb20
commit
307c5fa865
@ -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")
|
||||
}
|
||||
|
||||
|
14
worker.go
14
worker.go
@ -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
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user