Open rsc opened 4 months ago
package main import ( "net/http" "sync" ) func main() { var mu sync.Mutex defer mu.Unlock() http.DefaultClient.Transport.RoundTrip(new(http.Request)) }
% go run x.go fatal error: sync: unlock of unlocked mutex [signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x1001c3ed8] goroutine 1 [running]: sync.fatal({0x1001c9eb2?, 0x140000021c0?}) /Users/rsc/go/src/runtime/panic.go:1031 +0x20 sync.(*Mutex).unlockSlow(0x1400000e250, 0xffffffff) /Users/rsc/go/src/sync/mutex.go:229 +0x38 sync.(*Mutex).Unlock(...) /Users/rsc/go/src/sync/mutex.go:223 panic({0x1002337e0?, 0x100342140?}) /Users/rsc/go/src/runtime/panic.go:785 +0x124 main.main() /private/tmp/x.go:11 +0x68 exit status 2 %
Removing the sync.Mutex, the program crashes with
panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x102e43ea4] goroutine 1 [running]: main.main() /private/tmp/x.go:8 +0x34 exit status 2
Note that the panic text is missing from the original crash.
Just as nested panics print all the panic values, so too this fatal error should print the earlier panic value.
Change https://go.dev/cl/613757 mentions this issue: runtime: print the panic parameter when run defer occurs fatal
runtime: print the panic parameter when run defer occurs fatal
Removing the sync.Mutex, the program crashes with
Note that the panic text is missing from the original crash.
Just as nested panics print all the panic values, so too this fatal error should print the earlier panic value.