Skip to content

[coverage] Fix connection disposed error - #2903

Draft
liamappelbe wants to merge 4 commits into
mainfrom
coverage_connection_disposed
Draft

liamappelbe wants to merge 4 commits into
mainfrom
coverage_connection_disposed

Conversation

@liamappelbe

@liamappelbe liamappelbe commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

One way the connection disposed errors seen here could happen is:

  • The lambda in collect closes over the mutable variable service.
  • As of VM service v14.2.2, the dispose() call in onDone is redundant.
  • So if the retry loop triggered, the second try would overwrite the service variable with a new instance, and the first try would call dispose() on the second instance.
  • We were also only disposing the connection on TimeoutExceptions, which made the issue worse.

So the fix is to:

  • Refactor so that we're not closing over service.
  • Remove the redundant dispose().
  • Catch all exceptions, not just TimeoutException.
  • Bump the minimum VM service version to v14.2.2.

Integration test and fix based on dart-lang/sdk#64233 (comment)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request resolves a race condition in collect() during VM service connection retries by refactoring the connection logic into a dedicated _connect helper function and ensuring failed connection attempts are properly disposed. It also updates the vm_service package constraints and adds comprehensive tests in retry_connection_test.dart. The review feedback suggests removing a redundant as VmService cast since the type is already inferred, and forwarding WebSocket stream errors to the controller in _connect to prevent unhandled asynchronous errors.

Comment thread pkgs/coverage/lib/src/collect.dart Resolved
Comment thread pkgs/coverage/lib/src/collect.dart Resolved
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

PR Health

Publish ✔️
Package Version Status Publish tag (post-merge)
package:coverage ⭐ 1.16.2-wip WIP (no publish necessary)
  • 16 already published.
  • 26 WIP (no publish necessary).

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

This check can be disabled by tagging the PR with skip-publish-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check (for example, for non-user-visible changes when the package version is already at -wip).

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
coverage Non-Breaking 1.16.1 1.16.2-wip 1.16.2-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Unused Dependencies ✔️
Package Status
coverage ✔️ All dependencies utilized correctly.

For details on how to fix these, see dependency_validator.

This check can be disabled by tagging the PR with skip-unused-dependencies-check.

License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/html/test/differential_test.dart
pkgs/html/test/dom_parsing_test.dart
pkgs/html/test/mxss_test.dart
pkgs/html/test/noah_ark_clause_limit_test.dart

This check can be disabled by tagging the PR with skip-license-check.

Coverage ✔️
File Coverage
pkgs/coverage/lib/src/collect.dart 💚 87 % ⬆️ 1 %

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant