Support context cancellation in Gateway when serving car files #9065
Labels
kind/enhancement
A net-new feature or improvement to an existing feature
topic/gateway
Topic gateway
Milestone
Checklist
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 862ce6b, 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 bymerkledag.Walk
which only respects context cancellation in the parallel case, which requires an explicit concurrency option to be passed. Changingmerkledag.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 ipld/go-ipld-prime#154 and ipld/go-ipld-prime#303The text was updated successfully, but these errors were encountered: