Calling t.Fatal internally triggers runtime.Goexit . This kills the current goroutine while only running deferred code. Add an extra context that gets canceled if the go routine exits while within the user provided callback.