diff options
author | Jakob Borg <jakob@nym.se> | 2014-03-23 08:44:27 +0100 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-03-23 08:44:27 +0100 |
commit | 804cce7ba08b306b2d3a0755f6641a9f0904b2a3 (patch) | |
tree | 16141a0e51d2cd04de3a2d1e641ee765383514bf | |
parent | 6d7b001b0b37025b0e1bbc968d4fed9aacce7a3b (diff) |
Ensure that we make progress on the read side of a connection
-rw-r--r-- | protocol/protocol.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/protocol/protocol.go b/protocol/protocol.go index 0c5a0c0be4..101f12032e 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -177,6 +177,9 @@ func (c *Connection) Request(repo string, name string, offset int64, size int) ( return nil, ErrClosed } rc := make(chan asyncResult) + if _, ok := c.awaiting[c.nextID]; ok { + panic("id taken") + } c.awaiting[c.nextID] = rc header{0, c.nextID, messageTypeRequest}.encodeXDR(c.xw) _, err := RequestMessage{repo, name, uint64(offset), uint32(size)}.encodeXDR(c.xw) @@ -312,15 +315,17 @@ loop: break loop } - c.Lock() - rc, ok := c.awaiting[hdr.msgID] - delete(c.awaiting, hdr.msgID) - c.Unlock() + go func(hdr header, err error) { + c.Lock() + rc, ok := c.awaiting[hdr.msgID] + delete(c.awaiting, hdr.msgID) + c.Unlock() - if ok { - rc <- asyncResult{data, c.xr.Error()} - close(rc) - } + if ok { + rc <- asyncResult{data, err} + close(rc) + } + }(hdr, c.xr.Error()) case messageTypePing: c.Lock() |