A process can't use os/signal.Notify inside a goroutine to signal itself with SIGUSR2.
Works as expected (outside the goroutine):
func main() {
var c = make(chan os.Signal, 1)
signal.Notify(c) // outside the goroutine
var done = make(chan struct{})
go func() {
fmt.Println(<-c)
done <- struct{}{}
}()
if err := syscall.Kill(os.Getpid(), syscall.SIGUSR2); err != nil {
panic(err)
}
<-done
}
Doesn't work as expected (inside the goroutine):
func main() {
var done = make(chan struct{})
go func() {
var c = make(chan os.Signal, 1)
signal.Notify(c) // inside the goroutine
fmt.Println(<-c)
done <- struct{}{}
}()
if err := syscall.Kill(os.Getpid(), syscall.SIGUSR2); err != nil {
panic(err)
}
<-done
}
Expected: Doesn't hang
Actual: Hangs
The Notify documentation doesn't say it has to be called in the main goroutine.
A process can't use os/signal.Notify inside a goroutine to signal itself with SIGUSR2.
Works as expected (outside the goroutine):
Doesn't work as expected (inside the goroutine):
Expected: Doesn't hang
Actual: Hangs
The Notify documentation doesn't say it has to be called in the main goroutine.