lib/sync, lib/model: Capture locker routine ID, print locker details on deadlock
This commit is contained in:
@@ -173,8 +173,8 @@ func NewModel(cfg *config.Wrapper, id protocol.DeviceID, deviceName, clientName,
|
||||
// period.
|
||||
func (m *Model) StartDeadlockDetector(timeout time.Duration) {
|
||||
l.Infof("Starting deadlock detector with %v timeout", timeout)
|
||||
deadlockDetect(m.fmut, timeout)
|
||||
deadlockDetect(m.pmut, timeout)
|
||||
deadlockDetect(m.fmut, timeout, "fmut")
|
||||
deadlockDetect(m.pmut, timeout, "pmut")
|
||||
}
|
||||
|
||||
// StartFolder constructs the folder service and starts it.
|
||||
|
||||
@@ -7,11 +7,16 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func deadlockDetect(mut sync.Locker, timeout time.Duration) {
|
||||
type Holder interface {
|
||||
Holder() (string, int)
|
||||
}
|
||||
|
||||
func deadlockDetect(mut sync.Locker, timeout time.Duration, name string) {
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(timeout / 4)
|
||||
@@ -29,7 +34,12 @@ func deadlockDetect(mut sync.Locker, timeout time.Duration) {
|
||||
}()
|
||||
|
||||
if r := <-ok; !r {
|
||||
panic("deadlock detected")
|
||||
msg := fmt.Sprintf("deadlock detected at %s", name)
|
||||
if hmut, ok := mut.(Holder); ok {
|
||||
holder, goid := hmut.Holder()
|
||||
msg = fmt.Sprintf("deadlock detected at %s, current holder: %s at routine %d", name, holder, goid)
|
||||
}
|
||||
panic(msg)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user