mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-24 15:38:27 +00:00
Don't deadlock on connect close while sending Index (fixes #386)
This commit is contained in:
parent
4ab4816556
commit
33e9a35f08
@ -12,6 +12,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/calmh/syncthing/xdr"
|
"github.com/calmh/syncthing/xdr"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -84,6 +85,8 @@ type rawConnection struct {
|
|||||||
awaiting []chan asyncResult
|
awaiting []chan asyncResult
|
||||||
imut sync.Mutex
|
imut sync.Mutex
|
||||||
|
|
||||||
|
idxMut sync.Mutex // ensures serialization of Index calls
|
||||||
|
|
||||||
nextID chan int
|
nextID chan int
|
||||||
outbox chan []encodable
|
outbox chan []encodable
|
||||||
closed chan struct{}
|
closed chan struct{}
|
||||||
@ -142,6 +145,9 @@ func (c *rawConnection) ID() string {
|
|||||||
|
|
||||||
// Index writes the list of file information to the connected peer node
|
// Index writes the list of file information to the connected peer node
|
||||||
func (c *rawConnection) Index(repo string, idx []FileInfo) {
|
func (c *rawConnection) Index(repo string, idx []FileInfo) {
|
||||||
|
c.idxMut.Lock()
|
||||||
|
defer c.idxMut.Unlock()
|
||||||
|
|
||||||
c.imut.Lock()
|
c.imut.Lock()
|
||||||
var msgType int
|
var msgType int
|
||||||
if c.indexSent[repo] == nil {
|
if c.indexSent[repo] == nil {
|
||||||
@ -164,11 +170,11 @@ func (c *rawConnection) Index(repo string, idx []FileInfo) {
|
|||||||
}
|
}
|
||||||
idx = diff
|
idx = diff
|
||||||
}
|
}
|
||||||
|
c.imut.Unlock()
|
||||||
|
|
||||||
if len(idx) > 0 {
|
if len(idx) > 0 {
|
||||||
c.send(header{0, -1, msgType}, IndexMessage{repo, idx})
|
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.
|
// Request returns the bytes for the specified block after fetching them from the connected peer.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user