fix a panic caused by context cancelling closing a promise channel
Jeromy committed
Feb 12, 2015 at 19:53 UTC
de057f60dd339d796661a2fc1a46fb3f353a589c
1 file changed
+9
-1
exchange/bitswap/bitswap.go
+9
-1
@@ -151,7 +151,15 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
151
}
152
153
select {
154
- case block := <-promise:
154
+ case block, ok := <-promise:
155
+ if !ok {
156
+ select {
157
+ case <-ctx.Done():
158
+ return nil, ctx.Err()
159
+ default:
160
+ return nil, errors.New("promise channel was closed")
161
+ }
162
+ }
163
return block, nil
164
case <-parent.Done():
165
return nil, parent.Err()