mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-02 03:28:25 +08:00
Merge pull request #776 from jbenet/fix/mdag-panic
fix a panic caused by context cancelling closing a promise channel
This commit is contained in:
@ -151,7 +151,15 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
|
||||
}
|
||||
|
||||
select {
|
||||
case block := <-promise:
|
||||
case block, ok := <-promise:
|
||||
if !ok {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
default:
|
||||
return nil, errors.New("promise channel was closed")
|
||||
}
|
||||
}
|
||||
return block, nil
|
||||
case <-parent.Done():
|
||||
return nil, parent.Err()
|
||||
|
Reference in New Issue
Block a user