diff options
author | Jakob Borg <jakob@nym.se> | 2014-07-04 15:16:33 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-07-04 15:16:33 +0200 |
commit | a720f90a70f3ca21ab8eacb98788aa04e7aca704 (patch) | |
tree | cadd8b3618b0553e40f88f0caa0f578bd251c3f0 | |
parent | 4a6b43bcaec3f6deaf823e96746f725ef3e77a6b (diff) |
Don't leak writer and index goroutines on close
-rw-r--r-- | protocol/protocol.go | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/protocol/protocol.go b/protocol/protocol.go index 9977737d3d..e82fa756b1 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -332,11 +332,16 @@ func (c *rawConnection) indexSerializerLoop() { // 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 // routine and buffered channel. - for ii := range incomingIndexes { - if ii.update { - c.receiver.IndexUpdate(ii.id, ii.repo, ii.files) - } else { - c.receiver.Index(ii.id, ii.repo, ii.files) + for { + select { + case ii := <-incomingIndexes: + if ii.update { + 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() { var err error - for es := range c.outbox { - for _, e := range es { - e.encodeXDR(c.xw) - } + for { + select { + case es := <-c.outbox: + for _, e := range es { + e.encodeXDR(c.xw) + } - if err = c.flush(); err != nil { - c.close(err) + if err = c.flush(); err != nil { + c.close(err) + return + } + case <-c.closed: return } } |