Skip to content

runtime: sync fatal error swallows panic message #67792

@rsc

Description

@rsc
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions