Repository navigation
fix(dio): keep QueuedInterceptor callbacks serial after cancellation - #2648
Open
martinusgalih wants to merge 1 commit into
Open
martinusgalih wants to merge 1 commit into
martinusgalih wants to merge 1 commit into
Conversation
Release a cancelled QueuedInterceptor task only after its callback has returned, instead of immediately on cancellation. This preserves the serial guarantee for token-refresh style interceptors while still unblocking the queue when a cancelled callback returns without completing its handler. Closes cfug#2643 Co-Authored-By: OpenCode <noreply@opencode.ai> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2643.
When the active request of a
QueuedInterceptorwas cancelled, the queue released its slot immediately on cancellation, so the next queued callback could start while the cancelled callback was still running. With a token-refresh interceptor this runs two refreshes at once, which breaks the serial guaranteeQueuedInterceptorexists to provide. With the repro from the issue, the refresh runs twice before this change and once after.This change releases the slot on cancellation only after the cancelled callback has returned (either it completed the handler, or it returned without doing so after seeing the cancellation).
advancestays idempotent, so the normal path and the cancellation path cannot double-advance. ForQueuedInterceptorsWrapper, whose callbacks are typedvoid, the wrapper records the callback's runtimeFutureon the handler so the queue can wait for it.Trade-off to review
The existing test "should not stall the queue when the active request is cancelled mid-callback" asserted that the next request runs while the cancelled callback is still awaiting (a 5-second delay). That is exactly the overlap #2643 reports, so I changed that test to release the cancelled callback after cancellation instead of waiting on a fixed delay. The consequence: if a cancelled callback awaits a future that never completes, the queue now waits for it instead of moving on. I think serial execution is the right default for
QueuedInterceptor, but please say if you would rather keep the old release-on-cancel behaviour, for example behind an option.Testing
mainand passes with this change.dart analyzeanddart formatclean; fulldioVM test suite passes (254 passed, 6 skipped).Before / After
Test output as text
Before (main):
After (this PR),
dart test test/queued_interceptor_test.dart:AI disclosure: implementation and tests were written by OpenCode (DeepSeek); the diff was reviewed and the tests were re-run locally with Claude Opus 5.5 before submitting. I've read the change and will respond to review myself.
New Pull Request Checklist
mainbranch to avoid conflicts (via merge from master or rebase)CHANGELOG.mdin the corresponding package