Repository navigation
Conversation
…lientAdapter` When `connectTimeout` fires, the adapter stops waiting for `HttpClient.openUrl`, but the call keeps running and cannot be cancelled. If it completes later, e.g. after waiting for a free slot under `HttpClient.maxConnectionsPerHost`, the returned request holds a pooled connection that is never released. Enough of them occupy every slot of a host, and all later requests to it fail with `connectionTimeout` until the client is recreated. Abort that request when it arrives so the connection is released. Co-Authored-By: Claude <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 #2645.
When
connectTimeoutfires,IOHttpClientAdapterstops waiting forHttpClient.openUrl, but the call keeps running and cannot be cancelled. If it completes later, the returnedHttpClientRequestis never closed, so its connection is never released. WithHttpClient.maxConnectionsPerHostset, such requests can take every slot of a host, and all later requests to it fail withconnectionTimeoutuntil the client is recreated. The issue has the details and a pure Dart repro.The fix aborts that request when it arrives. Nothing changes for requests that do not time out, and the exception thrown on timeout is the same as before.
This touches timeout handling and connection pooling, which AGENTS.md lists as a sensitive area, so cc @AlexV525.
New Pull Request Checklist
mainbranch to avoid conflicts (via merge from master or rebase)CHANGELOG.mdin the corresponding packageAdditional context and info (if any)
Tests. The new test in
dio/test/timeout_test.dartfails without the change (the last request ends withconnectionTimeout) and passes with it.Locally, on Dart 3.12.2, I ran
dart format,dart analyzeanddart testfor thediopackage only.dart testends with 251 passed and 3 failed. The same 3 fail on an unmodifiedmainon my network, they all rely on a non-routable address:options_timeout_integration_test.dart: Options.connectTimeout is used by adaptertest_suite_test.dart: Timeout exception of connectTimeout throwstest_suite_test.dart: ignores zero duration timeoutsThat is why the "tests without failures" box is not ticked. I did not run the min SDK, web or Flutter suites.
No documentation change is needed, the public API is the same.
AI disclosure. The implementation, the test and this description were drafted with Claude Code (Claude) and reviewed by me.