diff options
author | Jakob Borg <jakob@nym.se> | 2014-06-21 09:43:12 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-06-21 12:35:53 +0200 |
commit | 4ab48165563861a9d82a4f7d717e0ec198958294 (patch) | |
tree | 965a7c6ba59aedafbe218e7f9bec6c309ad398ab | |
parent | 8e8a579bb20e22e09f720e78a278c7058465d54e (diff) |
Detect deadlock in model and panic
-rw-r--r-- | Godeps/Godeps.json | 2 | ||||
-rw-r--r-- | cmd/syncthing/usage_report.go | 1 | ||||
-rw-r--r-- | model/model.go | 4 | ||||
-rw-r--r-- | model/util.go | 26 |
4 files changed, 32 insertions, 1 deletions
diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 80dac66053..9ad57d4381 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,6 +1,6 @@ { "ImportPath": "github.com/calmh/syncthing", - "GoVersion": "go1.2.2", + "GoVersion": "go1.3", "Packages": [ "./cmd/syncthing", "./cmd/assets", diff --git a/cmd/syncthing/usage_report.go b/cmd/syncthing/usage_report.go index 430f9b8b33..cee7196aab 100644 --- a/cmd/syncthing/usage_report.go +++ b/cmd/syncthing/usage_report.go @@ -25,6 +25,7 @@ func reportData(m *model.Model) map[string]interface{} { res := make(map[string]interface{}) res["uniqueID"] = strings.ToLower(certID([]byte(myID)))[:6] res["version"] = Version + res["longVersion"] = LongVersion res["platform"] = runtime.GOOS + "-" + runtime.GOARCH res["numRepos"] = len(cfg.Repositories) res["numNodes"] = len(cfg.Nodes) diff --git a/model/model.go b/model/model.go index c87e5c11b4..e0ca693a54 100644 --- a/model/model.go +++ b/model/model.go @@ -15,6 +15,7 @@ import ( "path/filepath" "sync" "time" + "github.com/calmh/syncthing/cid" "github.com/calmh/syncthing/config" "github.com/calmh/syncthing/files" @@ -96,6 +97,9 @@ func NewModel(indexDir string, cfg *config.Configuration, clientName, clientVers sup: suppressor{threshold: int64(cfg.Options.MaxChangeKbps)}, } + deadlockDetect(&m.rmut, 60*time.Second) + deadlockDetect(&m.smut, 60*time.Second) + deadlockDetect(&m.pmut, 60*time.Second) go m.broadcastIndexLoop() return m } diff --git a/model/util.go b/model/util.go index 9445e61e63..35a620d096 100644 --- a/model/util.go +++ b/model/util.go @@ -7,6 +7,8 @@ package model import ( "fmt" "path/filepath" + "sync" + "time" "github.com/calmh/syncthing/protocol" "github.com/calmh/syncthing/scanner" @@ -90,3 +92,27 @@ func compareClusterConfig(local, remote protocol.ClusterConfigMessage) error { return nil } + +func deadlockDetect(mut sync.Locker, timeout time.Duration) { + go func() { + for { + time.Sleep(timeout / 4) + ok := make(chan bool, 2) + + go func() { + mut.Lock() + mut.Unlock() + ok <- true + }() + + go func() { + time.Sleep(timeout) + ok <- false + }() + + if r := <-ok; !r { + panic("deadlock detected") + } + } + }() +} |