summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob Borg <jakob@nym.se>2014-06-22 08:17:58 +0200
committerJakob Borg <jakob@nym.se>2014-06-22 08:17:58 +0200
commit33e9a35f08c3821f6683552fe767f80f82f49e0b (patch)
treee0e0f6a1f93b4d3056d150333918210dfd31c8f1
parent4ab48165563861a9d82a4f7d717e0ec198958294 (diff)
Don't deadlock on connect close while sending Index (fixes #386)
-rw-r--r--protocol/protocol.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/protocol/protocol.go b/protocol/protocol.go
index 75c304d084..20ef899594 100644
--- a/protocol/protocol.go
+++ b/protocol/protocol.go
@@ -12,6 +12,7 @@ import (
"io"
"sync"
"time"
+
"github.com/calmh/syncthing/xdr"
)
@@ -84,6 +85,8 @@ type rawConnection struct {
awaiting []chan asyncResult
imut sync.Mutex
+ idxMut sync.Mutex // ensures serialization of Index calls
+
nextID chan int
outbox chan []encodable
closed chan struct{}
@@ -142,6 +145,9 @@ func (c *rawConnection) ID() string {
// Index writes the list of file information to the connected peer node
func (c *rawConnection) Index(repo string, idx []FileInfo) {
+ c.idxMut.Lock()
+ defer c.idxMut.Unlock()
+
c.imut.Lock()
var msgType int
if c.indexSent[repo] == nil {
@@ -164,11 +170,11 @@ func (c *rawConnection) Index(repo string, idx []FileInfo) {
}
idx = diff
}
+ c.imut.Unlock()
if len(idx) > 0 {
c.send(header{0, -1, msgType}, IndexMessage{repo, idx})
}
- c.imut.Unlock()
}
// Request returns the bytes for the specified block after fetching them from the connected peer.