Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: sync fatal error swallows panic message #67792

Open
rsc opened this issue Jun 3, 2024 · 0 comments
Open

runtime: sync fatal error swallows panic message #67792

rsc opened this issue Jun 3, 2024 · 0 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jun 3, 2024

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.

@rsc rsc added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 3, 2024
@rsc rsc added this to the Go1.24 milestone Jun 3, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests

2 participants