flynn/flynn — pull request #628 by titanous (2014-12-19 22:10:06+00:00)
Title: test: Remove broken mutex optimizations in helper

These optimizations don’t actually improve much, and complicate things.

They also trigger a serious issue, due to the way gocheck is implemented. If an Assert fails, it calls runtime.Goexit, which will terminate the currently running goroutine. While terminating the goroutine, Goexit unwinds the stack and runs any deferred functions.

In the bad case, Assert will fail while a mutex is unlocked, and there will be another deferred Unlock, which will trigger a panic.

This panic will not have a complete stack trace due to golang/go#9404.

The solution is to treat t.Assert as code that looks like:

if err != nil {
return
}

and remember that all deferred functions will be run.