Skip to content

Conversation

simolus3
Copy link
Contributor

Starting from version 1.5.0 of package:http, some client implementations (including the default ones from that package) support cancelling requests (with a mechanism similar to AbortController in JS, represented as a future that, when completed, aborts the request).

While we are already handling cancellations quite well in our sync client implementation (we currently cancel the stream subscription on the HTTP stream, closing the underlying connection), one thing that's not currently cancellable is establishing the connection. Especially when the user has poor connectivity, waiting for headers to be received just to abort the request at that point can be inefficient. Adopting abortable requests can improve this.

By passing an abort trigger to the request, the client will behave as follows:

  1. If we abort the request before headers are completed (i.e., in .send()), send() itself will throw a RequestAbortedException, which extends ClientException.
  2. If we abort the request while we're listening to the stream, an RequestAbortedException is injected into the Dart stream by the client.

In both cases, we forward this exception on the stream that _dartSyncIteration and _ActiveRustStreamingIteration.receiveLines listen to, which will cause them to abort and rethrow. The exception is not visible to users because streamingSync catches it and does nothing if it hapens while aborting the sync.

@simolus3 simolus3 merged commit 0e8d50b into main Aug 11, 2025
5 checks passed
@simolus3 simolus3 deleted the request-cancellation branch August 11, 2025 14:21
@simolus3 simolus3 mentioned this pull request Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants