Skip to content

Latest commit

 

History

History
32 lines (25 loc) · 917 Bytes

README.md

File metadata and controls

32 lines (25 loc) · 917 Bytes

debugmutex

Build Status GoDoc

Mutex for debugging deadlocks. It can find non-obvious deadlocks in systems with heavy sync.Mutex usage. I found many deadlocks in Docker with it.

Usage

type Struct struct {
    sync.Locker
}

func New() *Struct {
    locker := &sync.Mutex{}
    if os.Getenv("DEBUG") != "" {
        // will crash program with traceback and file:line where deadlock is
        // occured after five tries to acquire mutex with 1 second gap between.
        locker = debugmutex.New(5, true)
    }
    return &Struct{Locker: locker}
}

For logging github.com/sirupsen/logrus is used. You can set debug logging with

logrus.SetLevel(logrus.DebugLevel)