ipfs / go-ipfs-api

The go interface to ipfs's HTTP API
MIT License
454 stars 178 forks source link

Support context.Context #293

Closed benny-conn closed 1 year ago

benny-conn commented 1 year ago

I wish I could use this library but because it does not support go's context.Context, I can't reliably use it. This library performs operations over a network and it is common practice to use a context so that network operations can be cancelled by the context, either by manual cancellation or deadline. The go http package supports contexts with functions like http.NewRequestWithContext.

Even if I use contexts and goroutines to disregard the response of a shell request when a context times out for example, there is no way to stop the execution of a function. If I were to be downloading content from ipfs, it would continue downloading despite the context cancelling, and the program continuing running.

The only workaround I can see is manually setting a timeout on the http client, but this is bad practice and not predictable.

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.

lidel commented 1 year ago

@benny-conn we are in the process of unifying our RPC client story (https://github.com/ipfs/kubo/issues/9124), so it is unlikely we will break/change API here until that issue is resolved (closing this, let's continue there).

For now, maybe you could see if https://github.com/ipfs/go-ipfs-http-client is enough for your use case?