ipfs / go-bitswap

The golang implementation of the bitswap protocol
MIT License
216 stars 112 forks source link

Cancelling session context kills bitswap client #594

Closed guillaumemichel closed 1 year ago

guillaumemichel commented 1 year ago

Cancelling the (parent) context of the GetBlock() / GetBlocks() methods makes Bitswap client fail constantly on future requests.

The following example illustrates the issue. kubo is slightly modified and runs the following.

bsCtx, cncl := context.WithDeadline(ctx, time.Now().Add(5*time.Second))

block, err := api.exchange.GetBlock(bsCtx, cid)
defer cncl()

If the bitswap request doesn't succeed in the 5 seconds, it will abort as expected and the function will return. However, all future bitswap requests will systematically fail, which is unexpected.

The following code snippet works as expected for multiple requests.

block, err := api.exchange.GetBlock(ctx, cid)

Something must be wrong in the Bitswap client implementation, probably in the way Sessions shutdown is handled in session.go.

welcome[bot] commented 1 year ago

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

Finally, remember to use https://discuss.ipfs.io if you just need general support.

guillaumemichel commented 1 year ago

The issue doesn't come from go-bitswap