incomingIndexes should not be a package variable (fixes #344)
This commit is contained in:
parent
37d83a4e2e
commit
a7b6e35467
|
@ -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 {
|
||||||
|
@ -121,21 +130,22 @@ func NewConnection(nodeID string, reader io.Reader, writer io.Writer, receiver M
|
||||||
wb := bufio.NewWriter(flwr)
|
wb := bufio.NewWriter(flwr)
|
||||||
|
|
||||||
c := rawConnection{
|
c := rawConnection{
|
||||||
id: nodeID,
|
id: nodeID,
|
||||||
receiver: nativeModel{receiver},
|
receiver: nativeModel{receiver},
|
||||||
state: stateInitial,
|
state: stateInitial,
|
||||||
reader: flrd,
|
reader: flrd,
|
||||||
cr: cr,
|
cr: cr,
|
||||||
xr: xdr.NewReader(flrd),
|
xr: xdr.NewReader(flrd),
|
||||||
writer: flwr,
|
writer: flwr,
|
||||||
cw: cw,
|
cw: cw,
|
||||||
wb: wb,
|
wb: wb,
|
||||||
xw: xdr.NewWriter(wb),
|
xw: xdr.NewWriter(wb),
|
||||||
awaiting: make([]chan asyncResult, 0x1000),
|
awaiting: make([]chan asyncResult, 0x1000),
|
||||||
idxSent: make(map[string]map[string]uint64),
|
idxSent: make(map[string]map[string]uint64),
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue