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

sync: unlocking an unlocked Mutex panics (should throw) #23039

rhysh opened this issue Dec 7, 2017 · 3 comments


None yet
3 participants
Copy link

commented Dec 7, 2017

What version of Go are you using (go version)?

go version go1.9.2 darwin/amd64
go version devel +28736053ad Wed Dec 6 15:50:04 2017 +0000 darwin/amd64

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

darwin/amd64, and the Go playground

What did you do?

defer func() { recover() }()


What did you expect to see?

I expected unlocking an unlocked sync.Mutex to lead to an unrecoverable fatal error, as it did in Go 1.8 and as unlocking an unlocked sync.RWMutex does today.

What did you see instead?

A couple of calls to throw were converted to panic calls as part of 0556e26, apparently unintentionally undoing a portion of 40d81cf.

$ cat /tmp/bug.go 
package main

import "sync"

func main() {
        defer func() { recover() }()
$ go1.7 run /tmp/bug.go
$ go1.8 run /tmp/bug.go
fatal error: sync: unlock of unlocked mutex

goroutine 1 [running]:
runtime.throw(0x10696e9, 0x1e)
        /usr/local/go/src/runtime/panic.go:596 +0x95 fp=0xc42003ff20 sp=0xc42003ff00
sync.throw(0x10696e9, 0x1e)
        /usr/local/go/src/runtime/panic.go:585 +0x35 fp=0xc42003ff40 sp=0xc42003ff20
        /usr/local/go/src/sync/mutex.go:113 +0xa4 fp=0xc42003ff68 sp=0xc42003ff40
        /tmp/bug.go:7 +0x57 fp=0xc42003ff88 sp=0xc42003ff68
        /usr/local/go/src/runtime/proc.go:185 +0x20a fp=0xc42003ffe0 sp=0xc42003ff88
        /usr/local/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc42003ffe8 sp=0xc42003ffe0
exit status 2
$ go1.9 run /tmp/bug.go
$ go-tip run /tmp/bug.go

This comment has been minimized.

Copy link

commented Dec 7, 2017

Probably too late for Go 1.10, especially since we shipped Go 1.9 with this, but I'm not overly concerned if it goes into Go 1.10 either.

/cc @dvyukov @ianlancetaylor

@bradfitz bradfitz added this to the Go1.11 milestone Dec 7, 2017


This comment has been minimized.

Copy link

commented Dec 7, 2017

Also @rsc.


This comment has been minimized.

Copy link

commented Dec 7, 2017

Change mentions this issue: sync: throw, not panic, for unlock of unlocked mutex

@gopherbot gopherbot closed this in f721966 Dec 8, 2017

@golang golang locked and limited conversation to collaborators Dec 8, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.