Repository navigation
[flutter_tools] Bound Browser.close in Chromium.close - #196211
auto-submit[bot] merged 9 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a 5-second timeout (kBrowserCloseTimeout) when sending the Browser.close command to Chrome, preventing Chromium.close from hanging indefinitely if Chrome exits before replying. A corresponding test is added to verify this behavior. Feedback suggests refactoring the new test to avoid using an unawaited asynchronous IIFE inside FakeAsync.run, which is an anti-pattern that can lead to flaky tests, and instead use a synchronous flow with .then() callbacks.
|
Addressed the Gemini inline feedback (medium) on What changed: drove Verified locally:
Per the template, Gemini feedback is trial/advisory and not authoritative — I verified the refactor myself (test still catches the unbounded |
|
Thanks for picking this up. I filed #196191 and the change looks right to me (not a maintainer, so not an approval). One optional refinement: in the case from the issue, Chrome has already exited when the reply goes missing, so await Future.any(<Future<void>>[
wipConnection.sendCommand('Browser.close'),
_process.exitCode,
]).timeout(kBrowserCloseTimeout);Untested sketch; an error from the losing future after the race settles is dropped by For reference, the package-side fix is google/webkit_inspection_protocol.dart#143. |
Wait for either the Browser.close reply or process exit, so an already-exited Chrome does not wait out kBrowserCloseTimeout. The timeout still covers a Chrome that is alive but unresponsive. Adds a test for the already-exited case. Co-authored-by: Jhin Lee <[email protected]>
14108ef to
52371a4
Compare
|
Thanks @leehack — took the refinement.
Added a regression test for the already-exited case ( Verified: Approach credited as |
bkonyi
left a comment
There was a problem hiding this comment.
This LGTM! We'll just need one more review before we can land this change.
| /// shutdown and escalating to SIGTERM/SIGKILL. | ||
| /// | ||
| /// The reply is raced against process exit, so a Chrome that already exited | ||
| /// returns immediately; this covers one that is alive but never answers. |
There was a problem hiding this comment.
If Chrome is alive but unresponsive, wouldn't we hang earlier in getChromeTabGuarded or tab.connect(), before reaching this timeout? Should the race + timeout wrap the whole graceful shutdown sequence instead of just Browser.close?
There was a problem hiding this comment.
Good catch — you're right, and yes, the earlier steps can block too: getChromeTabGuarded issues its HTTP request through HttpClient with no timeout of its own, and tab.connect() opens a WebSocket with no timeout either, so a Chrome that is alive but unresponsive could hang there before the Browser.close command is even sent.
I've bounded those steps with the same kBrowserCloseTimeout as well:
final ChromeTab? tab = await getChromeTabGuarded(
chromeConnection,
(_) => true,
retryFor: const Duration(seconds: 1),
).timeout(kBrowserCloseTimeout);
...
final WipConnection wipConnection = await tab.connect().timeout(kBrowserCloseTimeout);I bounded each step rather than wrapping the whole sequence in a single timeout: the steps are independent waits, so per-step timeouts give the same guarantee (no step of the graceful shutdown can hang forever) without restructuring close(). The Browser.close reply is still raced against the process exit, so a Chrome that already exited returns immediately.
Added a test for the case where Chrome never answers the tab lookup: Chromium close does not hang when Chrome never responds.
| await Future.any<void>(<Future<void>>[ | ||
| wipConnection.sendCommand('Browser.close'), | ||
| _process.exitCode, | ||
| ]).timeout(kBrowserCloseTimeout); |
There was a problem hiding this comment.
When this times out, we silently fall back to SIGTERM. Let's leave a trace so it's diagnosable with -v:
} on TimeoutException {
_logger.printTrace(
'Chrome did not respond to Browser.close within '
'${kBrowserCloseTimeout.inSeconds}s. Falling back to SIGTERM.',
);
} on IOException catch (_) {There was a problem hiding this comment.
Agreed — added a trace so the fallback is visible with -v:
} on TimeoutException {
_logger.printTrace(
'Chrome did not complete a graceful shutdown within '
'${kBrowserCloseTimeout.inSeconds}s. Falling back to SIGTERM.',
);
} on IOException catch (_) {printTrace only prints with -v, so the default output is unchanged. The new test asserts on logger.traceText.
Chrome can block at any step of the graceful shutdown: the HTTP request that locates the tab and the WebSocket handshake have no timeouts of their own, so a Chrome that is alive but unresponsive could hang before the Browser.close command is even sent. Bound the tab lookup and the handshake with kBrowserCloseTimeout as well, and log a trace when the timeout is hit so the fallback to SIGTERM is visible with -v.
|
@mdebbar Tell me what do you think now after the changes ? |
mdebbar
left a comment
There was a problem hiding this comment.
Thank you for fixing this!
|
auto label is removed for flutter/flutter/196211, Failed to enqueue flutter/flutter/196211 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected.. |
|
auto label is removed for flutter/flutter/196211, Failed to enqueue flutter/flutter/196211 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected.. |
|
autosubmit label was removed for flutter/flutter/196211, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
The The "Check Code Freeze" is apparently a bug in some Github Actions handling. The created checks remain pending until someone approves them manually in https://github.com/flutter/flutter/actions?query=is%3Aaction_required+workflow%3A%22Material+and+Cupertino+Code+Freeze%22 I approved them and will try again now. |
flutter/flutter@1b95854...d8bd864 2026-11-16 [email protected] Roll Skia from f2790b0ea630 to 118eaff3deb4 (8 revisions) (flutter/flutter#196661) 2026-11-16 [email protected] [native_assets] Keep a dylib's install name in flutter test when its path does not fit (flutter/flutter#194802) 2026-11-16 [email protected] Reland "[android]: prewarms shaders when the context is created" (flutter/flutter#196579) 2026-11-16 [email protected] [flutter_tools] Bound Browser.close in Chromium.close (flutter/flutter#196211) 2026-11-16 [email protected] Roll Skia from e8ff7a4187ec to f2790b0ea630 (13 revisions) (flutter/flutter#196652) 2026-11-14 [email protected] Revert: Balance web_canvaskit_tests and web_skwasm_tests subshards by duration (flutter/flutter#196580) 2026-11-14 [email protected] Revert: Reland "[android]: prewarms shaders when the context is created" (flutter/flutter#196575) 2026-11-14 [email protected] [flutter_tools] Guard ExtensionManager initialization against concurrent disposal (flutter/flutter#196459) 2026-11-14 [email protected] [ImpellerC] Escape spaces in depfile paths (flutter/flutter#196555) 2026-11-14 [email protected] Reland "[android]: prewarms shaders when the context is created" (flutter/flutter#196549) 2026-11-14 [email protected] Balance web_canvaskit_tests and web_skwasm_tests subshards by duration (flutter/flutter#196260) 2026-11-13 [email protected] Safely return null on malformed stack trace line in StackFrame.fromStackTraceLine (flutter/flutter#194673) 2026-11-13 [email protected] Clarify that super.dispose() must be called synchronously (flutter/flutter#193416) 2026-11-13 [email protected] Consolidate exit-code parameters on runCommand with ExpectedExit (flutter/flutter#196479) 2026-11-13 [email protected] Support multi-view apps in widget test binding (flutter/flutter#194480) 2026-11-13 [email protected] Document using a ListView inside a Column (flutter/flutter#195145) 2026-11-13 [email protected] Add didChangeAlwaysUse24HourFormat to WidgetsBinding and update MediaQuery (flutter/flutter#196117) 2026-11-13 [email protected] Build local engine wasm configs on 32-core Linux bots (flutter/flutter#196284) 2026-11-13 [email protected] [Android] Fix Hybrid Composition resize deadlock (flutter/flutter#196255) 2026-11-13 [email protected] Roll Skia from 11f46cfe8838 to e8ff7a4187ec (9 revisions) (flutter/flutter#196557) 2026-11-13 [email protected] [Impeller] Fix SurfaceContextVK submission tracking and double HostBuffer reset (flutter/flutter#196064) 2026-11-13 [email protected] Manual roll Packages from 14f9933 to 015df97 (5 revisions) (flutter/flutter#196558) 2026-11-13 [email protected] Remove routes_transition_test from widgets (flutter/flutter#186620) 2026-11-13 [email protected] [flutter_tools] Replace TargetPlatform.simpleName with cpuArch (flutter/flutter#196264) 2026-11-13 [email protected] Add a deferred platform-view-created path to the shell and use it on Android (flutter/flutter#196342) 2026-11-13 [email protected] Optimize RenderSliverVariedExtentList and introduce protected itemExtentOf API in RenderSliverFixedExtentBoxAdaptor (flutter/flutter#192384) 2026-11-13 [email protected] Revert: [android]: prewarms shaders when the context is created (flutter/flutter#196468) If this roll has caused a breakage, revert this CL and set the roller to dry run mode using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Bounds the
Browser.closewait inChromium.close()(flutter_tools/lib/src/web/chrome.dart) with a 5-second timeout (kBrowserCloseTimeout). On timeout,close()falls through to the existing SIGTERM/SIGKILL escalation instead of hanging forever.Root cause: when Chrome exits before its
Browser.closereply arrives, the pending command future inwebkit_inspection_protocolnever completes (_handleClosecloses its streams without completing pending completers), soawait wipConnection.sendCommand('Browser.close')never returns. This hungflutter test --platform chromeafter tests had already passed.Fix: the graceful shutdown is bounded by
kBrowserCloseTimeoutat every step — the tab lookup (getChromeTabGuarded), the WebSocket handshake (tab.connect()) and theBrowser.closecommand, which is also raced against_process.exitCodeso a Chrome that already exited returns immediately. The resultingTimeoutExceptionis caught by a dedicatedon TimeoutExceptionclause that logs a trace (visible with-v) and proceeds to_process.exitCodeSIGTERM (immediate, sincesigtermDelaystays zero) → SIGKILL → warning escalation. No newglobals.*use, no newdart:ioimports; timeout constant is@visibleForTestinglikekDevToolsListeningTimeout.Adds regression tests
Chromium close does not hang when Browser.close never repliesandChromium close does not hang when Chrome never responds(test/web.shard/chrome_test.dart) with aFakeWipConnectionwhoseBrowser.closefuture never completes and aFakeChromeConnectionWithTabwhose tab lookup never replies, driven byFakeAsync. On the old code these tests hang forever; with the fix they complete via SIGTERM fallback. Existingweb.shard/chrome_test.dartpasses (39 tests).Fixes #196191.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.