incomingIndexes should not be a package variable (fixes #344)
This commit is contained in:
@@ -97,6 +97,15 @@ type rawConnection struct {
|
|||||||
outbox chan []encodable
|
outbox chan []encodable
|
||||||
closed chan struct{}
|
closed chan struct{}
|
||||||
once sync.Once
|
once sync.Once
|
||||||
|
|
||||||
|
incomingIndexes chan incomingIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
type incomingIndex struct {
|
||||||
|
update bool
|
||||||
|
id string
|
||||||
|
repo string
|
||||||
|
files []FileInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
type asyncResult struct {
|
type asyncResult struct {
|
||||||
@@ -136,6 +145,7 @@ func NewConnection(nodeID string, reader io.Reader, writer io.Writer, receiver M
|
|||||||
outbox: make(chan []encodable),
|
outbox: make(chan []encodable),
|
||||||
nextID: make(chan int),
|
nextID: make(chan int),
|
||||||
closed: make(chan struct{}),
|
closed: make(chan struct{}),
|
||||||
|
incomingIndexes: make(chan incomingIndex, 100), // should be enough for anyone, right?
|
||||||
}
|
}
|
||||||
|
|
||||||
go c.indexSerializerLoop()
|
go c.indexSerializerLoop()
|
||||||
@@ -316,15 +326,6 @@ func (c *rawConnection) readerLoop() (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type incomingIndex struct {
|
|
||||||
update bool
|
|
||||||
id string
|
|
||||||
repo string
|
|
||||||
files []FileInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
var incomingIndexes = make(chan incomingIndex, 100) // should be enough for anyone, right?
|
|
||||||
|
|
||||||
func (c *rawConnection) indexSerializerLoop() {
|
func (c *rawConnection) indexSerializerLoop() {
|
||||||
// We must avoid blocking the reader loop when processing large indexes.
|
// We must avoid blocking the reader loop when processing large indexes.
|
||||||
// There is otherwise a potential deadlock where both sides has the model
|
// There is otherwise a potential deadlock where both sides has the model
|
||||||
@@ -334,7 +335,7 @@ func (c *rawConnection) indexSerializerLoop() {
|
|||||||
// routine and buffered channel.
|
// routine and buffered channel.
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case ii := <-incomingIndexes:
|
case ii := <-c.incomingIndexes:
|
||||||
if ii.update {
|
if ii.update {
|
||||||
c.receiver.IndexUpdate(ii.id, ii.repo, ii.files)
|
c.receiver.IndexUpdate(ii.id, ii.repo, ii.files)
|
||||||
} else {
|
} else {
|
||||||
@@ -360,7 +361,7 @@ func (c *rawConnection) handleIndex() error {
|
|||||||
// update and can't receive the large index update from the
|
// update and can't receive the large index update from the
|
||||||
// other side.
|
// other side.
|
||||||
|
|
||||||
incomingIndexes <- incomingIndex{false, c.id, im.Repository, im.Files}
|
c.incomingIndexes <- incomingIndex{false, c.id, im.Repository, im.Files}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -371,7 +372,7 @@ func (c *rawConnection) handleIndexUpdate() error {
|
|||||||
if err := c.xr.Error(); err != nil {
|
if err := c.xr.Error(); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
incomingIndexes <- incomingIndex{true, c.id, im.Repository, im.Files}
|
c.incomingIndexes <- incomingIndex{true, c.id, im.Repository, im.Files}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user