fix: service group not working well when callback takes long time (#4531)

Signed-off-by: kevin <wanjunfeng@gmail.com>
This commit is contained in:
Kevin Wan
2025-01-01 15:06:50 +08:00
committed by GitHub
parent 5c3679ffe7
commit fcc246933c
5 changed files with 66 additions and 2 deletions

View File

@@ -76,9 +76,14 @@ func (sg *ServiceGroup) doStart() {
}
func (sg *ServiceGroup) doStop() {
group := threading.NewRoutineGroup()
for _, service := range sg.services {
service.Stop()
// new variable to avoid closure problems, can be removed after go 1.22
// see https://golang.org/doc/faq#closures_and_goroutines
service := service
group.Run(service.Stop)
}
group.Wait()
}
// WithStart wraps a start func as a Service.