Repository navigation
Replace dynamic free-port probing with OS port-0 binding - #194419
Conversation
Replaces dynamic socket free-port probing (OperatingSystemUtils.findFreePort and findAvailablePortAndPossiblyCauseFlakyTests) with OS port-0 binding to prevent TOCTOU race conditions and test flakes across Chrome, ChromeDriver, and web test runners. Chromium is launched with --remote-debugging-port=0 when debugPort is not explicitly set, parsing the bound DevTools WebSocket URL from stderr. ChromeDriver is launched with --port=0, parsing the bound port from stdout. Bot and devicelab test servers bind to port 0 directly. Fixes flutter#194313
There was a problem hiding this comment.
Code Review
This pull request replaces flaky port-finding logic with port-0 binding, allowing the OS kernel to allocate ephemeral ports atomically when launching Chrome and ChromeDriver, and parses the bound port from the DevTools output. The review feedback suggests updating resolvePort to accept a nullable integer to prevent compilation errors, and throwing a StateError in browser.dart if the debugging port resolves to zero to avoid connection hangs.
|
This seems like the most likely cause of failures on web-tool-tests: https://ci.chromium.org/ui/p/dart/builders/ci.sandbox/flutter-linux-web-tool-tests/15055/blamelist |
http://dart-review.googlesource.com/c/monorepo/+/567140 should resolve those failures. |
) Replaces dynamic socket free-port probing (`OperatingSystemUtils.findFreePort` and `findAvailablePortAndPossiblyCauseFlakyTests`) with OS port-0 binding across Chrome, ChromeDriver, and web test runners to prevent TOCTOU race conditions and test flakes. Part of flutter#194313
…utter#196150) Follow-up to flutter#194419. On Linux, `chromedriver --port=0` [binds `::1` first](https://github.com/chromium/chromium/blob/de4e5d6e13b995f5e04137970c0e8ec456017467/chrome/test/chromedriver/server/chromedriver_server.cc#L172-L175) and then [binds `127.0.0.1` on the same port, exiting if it's taken](https://github.com/chromium/chromium/blob/de4e5d6e13b995f5e04137970c0e8ec456017467/chrome/test/chromedriver/server/chromedriver_server.cc#L225-L231). The port the OS picks for `::1` can still be in use on `127.0.0.1`, so `hot_reload_web_server_test` and `hot_restart_web_server_test` occasionally fail with: ``` chromedriver stdout: IPv4 port not available. Exiting... ``` Example CI failures: - https://ci.chromium.org/b/8666997626110753073 - https://ci.chromium.org/b/8665892656502980097 This PR restarts chromedriver (up to 3 attempts) when it exits with that message. Each attempt gets a new port from the OS. I reproduced it locally by holding some IPv4 ports in a network namespace with a narrow ephemeral port range: successful launches went from 9/15 to 14/15. ChromeDriver bug: https://issues.chromium.org/issues/582923020 Part of flutter#194313
Replaces dynamic socket free-port probing (
OperatingSystemUtils.findFreePortandfindAvailablePortAndPossiblyCauseFlakyTests) with OS port-0 binding across Chrome, ChromeDriver, and web test runners to prevent TOCTOU race conditions and test flakes.Part of #194313