Search code examples
goruntime-error

Go "panic: sync: unlock of unlocked mutex" without a known reason


I have a cli application in Go (still in development) and no changes were made in source code neither on dependencies but all of a sudden it started to panic panic: sync: unlock of unlocked mutex.

The only place I'm running concurrent code is to handle when program is requested to close:

func handleProcTermination() {
    c := make(chan os.Signal, 1)
    signal.Notify(c, os.Interrupt)
    go func() {
        <-c
        curses.Endwin()
        os.Exit(0)
    }()
    defer curses.Endwin()
}

Only thing I did was to rename my $GOPATH and work space folder. Can this operation cause such error?

Have some you experienced any related problem without having any explanation? Is there a rational check list that would help to find the cause of the problem?


Solution

  • Ok, after some unfruitful debugging sessions, as a last resort, I simply wiped all third party code (dependencies) from the workspace:

    cd $GOPATH
    rm -rf pkg/ bin/ src/github.com  src/golang.org # the idea is to remove all except your own source
    

    Used go get to get all used dependencies again:

    go get github.com/yadayada/yada
    go get # etc
    

    And the problem is gone! Application is starting normally and tests are passing. No startup panics anymore. It looks like this problem happens when you mv your work space folder but I'm not 100% sure yet. Hope it helps someone else.

    From now on, re install dependencies will be my first step when weird panic conditions like that suddenly appear.