kubo icon indicating copy to clipboard operation
kubo copied to clipboard

Support context cancellation in Gateway when serving car files

Open iand opened this issue 3 years ago • 5 comments

Checklist

  • [X] My issue is specific & actionable.
  • [X] I am not suggesting a protocol enhancement.
  • [X] I have searched on the issue tracker for my issue.

Description

This is a low priority general enhancement to conserve resources when dealing with slow clients. Car files may be very large and take a long time to transfer and we should respect cancellation of the request context (due to timeout or explicit).

As of commit 862ce6bb8f6ce24b91ed3dc59e7406faed34f583, car files are served in a single non-cancelable call https://github.com/ipfs/go-ipfs/blob/862ce6bb8f6ce24b91ed3dc59e7406faed34f583/core/corehttp/gateway_handler_car.go#L76

Supporting context cancellation would require go-car to support cancellation when writing and traversing a dag. Currently go-car v1 is being used. The top level function WriteCar accepts a context but it is not used for cancellation. The bulk of the work is performed by merkledag.Walk which only respects context cancellation in the parallel case, which requires an explicit concurrency option to be passed. Changing merkledag.sequentialWalkDepth to check for context cancellation would work here.

Alternatively switching to go-car v2 is an option, using NewSelectiveWriter but this would also require cancellation behavior to be pushed down into go-ipld-prime's traversal package. But see https://github.com/ipld/go-ipld-prime/issues/154 and https://github.com/ipld/go-ipld-prime/issues/303

iand avatar Jun 28 '22 15:06 iand

@schomatis mind adding this to your queue?

Only ask from my end is to keep returning CAR v1.

lidel avatar Jul 19 '22 12:07 lidel

@lidel Can I have some context on https://github.com/ipfs/kubo/pull/8758, please? Contrary to what I'm reading from Ian we seem to be in IPLD land and not merkledag (I'm only familiar with the second). I'm looking at traverseBlocks()/walkAdv_iterateSelective() but have no idea where is the traversal actually taking place and where would I plumb the context.

schomatis avatar Jul 22 '22 00:07 schomatis

See https://github.com/ipfs-shipyard/gateway-prime (here) for a version of the gateway that uses IPLD and go-car v2

iand avatar Jul 22 '22 11:07 iand

Thanks for the reference @iand. I'm still not sure if that is an answer to my request above or some more general context.

schomatis avatar Jul 22 '22 15:07 schomatis

Thanks for the reference @iand. I'm still not sure if that is an answer to my request above or some more general context.

Just general context

iand avatar Jul 24 '22 13:07 iand