Thank you Jan, that makes sense. On Wednesday, October 29, 2025 at 4:12:16 PM UTC+1 Jan Mercl wrote:
> On Wed, Oct 29, 2025 at 4:01 PM [email protected] <[email protected]> wrote: > > > > tl;dr Why does Go choose not to exit cleanly when there are no more > goroutines to run? > > > > Background: > > > > As part of a Go pub quiz, I asked the question: > > > > What always happens when this code runs? > > https://go.dev/play/p/opTvk1x-uAm > > > > Specifically, the code calls runtime.Goexit in the main goroutine. At > termination, the program prints: > > > > fatal error: no goroutines (main called runtime.Goexit) - deadlock! > > > > Why is this considered a fatal error? Obviously there are no more > goroutines to run, but why not exit cleanly in this case? > > > > Obviously there's a very good reason for this behavior. I just can't > work out what it is. > > If the runtime cleanly exits on a deadlock then we no longer can > detect unexpected deadlocks. Neither can we say if all "goroutines > terminated" is expected or not. Hence "clean exit" iff main() returns. > (Let's ignore os.Exit(rc) for a second.) > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/63369e4e-5908-4665-a687-d38a84d61614n%40googlegroups.com.
