Don't leak writer and index goroutines on close

This commit is contained in:
Jakob Borg 2014-07-04 15:16:33 +02:00
parent 4a6b43bcae
commit a720f90a70
1 changed files with 21 additions and 11 deletions

View File

@ -332,11 +332,16 @@ func (c *rawConnection) indexSerializerLoop() {
// large index update from the other side. But we must also ensure to // large index update from the other side. But we must also ensure to
// process the indexes in the order they are received, hence the separate // process the indexes in the order they are received, hence the separate
// routine and buffered channel. // routine and buffered channel.
for ii := range incomingIndexes { for {
if ii.update { select {
c.receiver.IndexUpdate(ii.id, ii.repo, ii.files) case ii := <-incomingIndexes:
} else { if ii.update {
c.receiver.Index(ii.id, ii.repo, ii.files) c.receiver.IndexUpdate(ii.id, ii.repo, ii.files)
} else {
c.receiver.Index(ii.id, ii.repo, ii.files)
}
case <-c.closed:
return
} }
} }
} }
@ -450,13 +455,18 @@ func (c *rawConnection) send(h header, es ...encodable) bool {
func (c *rawConnection) writerLoop() { func (c *rawConnection) writerLoop() {
var err error var err error
for es := range c.outbox { for {
for _, e := range es { select {
e.encodeXDR(c.xw) case es := <-c.outbox:
} for _, e := range es {
e.encodeXDR(c.xw)
}
if err = c.flush(); err != nil { if err = c.flush(); err != nil {
c.close(err) c.close(err)
return
}
case <-c.closed:
return return
} }
} }