2014-12-04 23:49



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() {
    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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • douxi3554 douxi3554 7年前

    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/  src/ # the idea is to remove all except your own source

    Used go get to get all used dependencies again:

    go get
    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.

    点赞 评论 复制链接分享
  • dongpi9164 dongpi9164 7年前

    You're not giving much information to go on, so my answer is generic.

    In theory, bugs in concurrent code can remain unnoticed for a long time and then suddenly show up. In practice, if the bug is easily repeatable (happens nearly every run) this usually indicates that something did change in the code or environment.

    The solution: debug. Knowing what has changed can be helpful to identify the bug. In this case, it appears that lock/unlock pairs or not matching up. If you are not passing locks between threads, you should be able to find a code path within the thread that has not acquired the lock, or has released it early. It may be helpful to put assertions at certain points to validate that you are holding the lock when you think you are.

    点赞 评论 复制链接分享