Skip to content

[dwds] Let the OS pick the port when starting HTTP servers - #2877

Closed
mdebbar wants to merge 1 commit into
dart-lang:mainfrom
mdebbar:fix-extension-backend-port-collision
Closed

mdebbar wants to merge 1 commit into
dart-lang:mainfrom
mdebbar:fix-extension-backend-port-collision

Conversation

@mdebbar

@mdebbar mdebbar commented Oct 12, 2026

Copy link
Copy Markdown

Flutter's Mac web_tool_tests has been flaking for months because the extension backend can't start:

SocketException: Failed to create server socket (OS Error: Address already in use, errno = 48), address = ::, port = 49158
  #4 startHttpServer (package:dwds/src/utilities/server.dart:49:20)
  #5 ExtensionBackend.start (package:dwds/src/servers/extension_backend.dart:63:20)

Flutter passes hostname any by default, and HttpMultiServer.bind('any', port) binds [::] dual-stack. But the port comes from findUnusedPort(), which only checks [::1] with v6Only: true. That port can still be held over IPv4, so the dual-stack bind fails. Every retry uses the same probe, and in all of these failures all 5 attempts failed (~500ms before the error).

Example CI failures:

This PR binds port 0 on the actual address, so the OS picks a port that's free for that exact bind. A requested port (e.g. the debug service's 44456) is still tried first, and the retry loop stays. #1451 moved away from port 0 because a single bind attempt failed without retrying (flutter/flutter#93256), so the retries still cover that case.

I confirmed the mismatch on Linux: with 127.0.0.1:P or 0.0.0.0:P held, a [::1] v6Only bind on P succeeds and a [::] bind on P fails with EADDRINUSE. There's no deterministic regression test because the failure depends on which port the kernel hands out.

Related to flutter/flutter#185452

@bkonyi

bkonyi commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

This LGTM, but would you mind moving this over into the Dart SDK's pkg/dwds? We're in the middle of migrating DWDS development into the SDK and we're treating that version as the source of truth.

@mdebbar

mdebbar commented Oct 13, 2026

Copy link
Copy Markdown
Author

@bkonyi Done: dart-lang/sdk#64580

@mdebbar mdebbar closed this Oct 13, 2026
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.

2 participants