Skip to content

Fix deadlock waiting on serverSocket - #2740

Merged
natebosch merged 58 commits into
masterfrom
unawaited-socket-cancel
Sep 1, 2026
Merged

natebosch merged 58 commits into
masterfrom
unawaited-socket-cancel

Conversation

@natebosch

@natebosch natebosch commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

Work around, and reduce the odds of triggering, a bug in the Dart SDK
implementation of unix domain sockets on windows.

dart-lang/sdk#64166

On windows in Dart sockets are being inherited by subprocesses, so
spawned test processes (like the chrome browser) would inherit them, and
subsequently after receiving a connection the socket cancel would never
complete (waiting on subprocess which inherited the socket to exit) so
the Stream.first future would also never complete. This surfaced as a
deadlock only in the case where a browser startup happens while the
socket server is waiting for the first connection.

Drastically reduce the odds of this situation by waiting to bind the
socket server until the subprocess is about to start, instead of
listening on the socket during the compilation process as well.

Work around the situation in case it still happens with a fastFirst
extension which behaves like first except it explicitly does not await
the Future returned from cancel.

Add an integration test which demonstrates the conditions required to
trigger the bug. We can remove this after the SDK is fixed.

On Windows the `subscription.cancel()` waits for an OS interaction that
never occurs and `stream.first` returns a Future that does not complete
until the cancellation completes.

Unskip tests on windows failing for this reason.
@github-actions

github-actions Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

PR Health

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.

@github-actions github-actions Bot added the type-infra A repository infrastructure change or enhancement label Aug 28, 2026
Comment thread .github/workflows/repro.yaml Fixed
@github-actions github-actions Bot removed the type-infra A repository infrastructure change or enhancement label Aug 28, 2026
@github-actions github-actions Bot added the type-infra A repository infrastructure change or enhancement label Aug 28, 2026
@github-actions github-actions Bot removed package:checks Issues related to pkg:checks package:matcher labels Aug 28, 2026
@natebosch
natebosch marked this pull request as ready for review August 28, 2026 21:42
@natebosch
natebosch requested a review from a team as a code owner August 28, 2026 21:42
@natebosch
natebosch requested a review from brianquinlan August 28, 2026 21:42

@brianquinlan brianquinlan 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.

That's a bit ugly but I don't have a better solution.

var socket = await serverSocket.first;
```

On Windows, this interacts with two platform-level behaviors:

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.

Optional: Are you going to clean up this text when your SDK fix is live? Maybe you could just point to an issue?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it would be OK to drop the whole directory after the min SDK dependency has a fix.

}

// TODO(https://github.com/dart-lang/sdk/issues/64166) remove when the min SDK
// does not leak sockets to subproceesses.

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.

You could add the note to remove the test or at least remove the docs for the test here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a note to remove the test.

@natebosch
natebosch merged commit 575e4da into master Sep 1, 2026
71 checks passed
@natebosch
natebosch deleted the unawaited-socket-cancel branch September 1, 2026 00:01
natebosch added a commit that referenced this pull request Sep 2, 2026
Work around, and reduce the odds of triggering, a bug in the Dart SDK
implementation of unix domain sockets on windows.

dart-lang/sdk#64166

On windows in Dart sockets are being inherited by subprocesses, so
spawned test processes (like the chrome browser) would inherit them, and
subsequently after receiving a connection the socket cancel would never
complete (waiting on subprocess which inherited the socket to exit) so
the `Stream.first` future would also never complete. This surfaced as a
deadlock only in the case where a browser startup happens while the
socket server is waiting for the first connection.

Drastically reduce the odds of this situation by waiting to bind the
socket server until the subprocess is about to start, instead of
listening on the socket during the compilation process as well.

Work around the situation in case it still happens with a `fastFirst`
extension which behaves like `first` except it explicitly does not await
the Future returned from `cancel`.

Add an integration test which demonstrates the conditions required to
trigger the bug. We can remove this after the SDK is fixed.
natebosch added a commit to dart-lang/ai that referenced this pull request Sep 4, 2026
Closes dart-lang/test#2688

The deadlock was caused by an interaction between chrome and exe tests where the chrome process was inheriting the socket server bound to communicate with the exe test.

Workaround landed in dart-lang/test#2740
copybara-service Bot pushed a commit to dart-lang/sdk that referenced this pull request Sep 4, 2026
Revisions updated by `dart tools/rev_sdk_deps.dart test`.

test (https://github.com/dart-lang/test/compare/55b186d..18ef597):
  18ef5978  Fri Sep 4 10:13:39 2026 -0700  Nate Bosch  Add support for collapsed error messages (dart-lang/test#2651)
  6783445c  Wed Sep 2 16:46:04 2026 -0700  Nate Bosch  Prepare to publish (dart-lang/test#2737)
  8de693e1  Tue Sep 1 03:54:15 2026 +0000  dependabot[bot]  Bump the github-actions group with 2 updates (dart-lang/test#2744)
  575e4dad  Mon Aug 31 17:01:46 2026 -0700  Nate Bosch  Fix deadlock waiting on serverSocket (dart-lang/test#2740)
  bd9acf32  Thu Aug 27 22:53:54 2026 -0700  Nate Bosch  Unskip a test on windows (dart-lang/test#2741)
  b575eda9  Thu Aug 27 17:16:16 2026 -0700  Nate Bosch  Remove redundant tag (dart-lang/test#2738)
  d21b06cb  Thu Aug 27 16:38:17 2026 -0700  dependabot[bot]  Bump the github-actions group across 1 directory with 5 updates (dart-lang/test#2709)
  773bc56c  Thu Aug 27 16:11:00 2026 -0700  Nate Bosch  Use read permissions in test_descriptor and test_process workflows (dart-lang/test#2736)
  73e85f1b  Wed Aug 26 06:36:41 2026 +0700  herdiyanitdev  Precompiled browser tests: stop serving files from outside the precompiled root (dart-lang/test#2724)
  bbe8f9bf  Tue Aug 18 09:02:24 2026 -0700  Kevin Moore  Export TestFailure from package:test_api/scaffolding.dart (dart-lang/test#2723)

TAG=agy
CONV=e6fd1c32-ded3-443f-83e5-2e15b4ffaccb
[email protected]

Change-Id: Iabc67d46c413470f0d2e5341e719d4edf702a94b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/546020
Commit-Queue: Nate Bosch <[email protected]>
Auto-Submit: Nate Bosch <[email protected]>
Reviewed-by: Kevin Moore <[email protected]>
Commit-Queue: Kevin Moore <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package:test type-infra A repository infrastructure change or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants