Skip to content

[flutter_tools] Preserve rolling log buffer for Chromium crash diagnostics - #196037

Merged
auto-submit[bot] merged 4 commits into
flutter:masterfrom
mehmetbahadirgungor:fix-chromium-crash-diagnostics
Nov 21, 2026
Merged

auto-submit[bot] merged 4 commits into
flutter:masterfrom
mehmetbahadirgungor:fix-chromium-crash-diagnostics

Conversation

@mehmetbahadirgungor

@mehmetbahadirgungor mehmetbahadirgungor commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #195823

Description

During Chromium process launch in ChromiumLauncher._spawnChromiumProcess, standard output and standard error streams are decoded and buffered into a rolling 200-line ListQueue<String> (logBuffer). When "DevTools listening" is detected on stderr, _spawnChromiumProcess unblocks and returns _SpawnResult(process, port, host, logBuffer.toList()).

Because logBuffer.toList() created a point-in-time snapshot of the queue into a separate List at early startup, subsequent log entries delivered by Chromium to the stream listeners after "DevTools listening" were not reflected in Chromium._logBuffer. When Chromium crashed unexpectedly with a non-zero exit code during test execution or application runtime, the crash diagnostics output printed only the early startup messages rather than the logs accumulated during runtime.

This PR preserves the live Iterable<String> reference to logBuffer across _SpawnResult and Chromium, ensuring that:

  1. Chromium._logBuffer retains the latest lines received by the stdout and stderr stream listeners throughout the Chromium process lifetime.
  2. Older entries beyond the 200-line limit continue to be evicted dynamically via the rolling ListQueue<String>.
  3. Crash diagnostics printed on unexpected non-zero exit codes contain the latest 200 log lines received by the listeners prior to crash handling.
  4. Process retries, glibc error retries, and D-Bus error filtering remain strictly isolated to their corresponding Chromium process.

Tests

Added automated regression coverage to packages/flutter_tools/test/web.shard/chrome_test.dart:

  • logs produced after "DevTools listening" appear in crash diagnostics: Verifies stdout and stderr messages received by listeners after DevTools listening are preserved and displayed in unexpected exit diagnostics.
  • older log entries are evicted once 200-line limit is exceeded: Emits 250 log lines and verifies that early lines are evicted while the latest 200 lines are preserved.
  • the correct logs are associated with the correct Chromium process across retries: Verifies that failed launch attempt logs are not attributed to the subsequent successfully launched process.
  • clean exit does not log unexpected crash diagnostics: Verifies clean termination does not log crash diagnostics.
  • chrome.close does not log unexpected crash diagnostics: Verifies clean shutdown via close() does not log crash diagnostics even if exit code is non-zero.

Targeted Verification Results:

  • bin/cache/dart-sdk/bin/dart format packages/flutter_tools/lib/src/web/chrome.dart packages/flutter_tools/test/web.shard/chrome_test.dart (Clean).
  • bin/cache/dart-sdk/bin/dart analyze packages/flutter_tools (No issues found!).
  • bin/flutter test packages/flutter_tools/test/web.shard/chrome_test.dart (All 41 tests passed).

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the AI contribution guidelines and understand my responsibilities, or I am not using AI tools.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant in-code documentation (doc comments with ///).
  • If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in flutter/website (or verified none is needed).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • I followed the breaking change policy and added Data Driven Fixes where supported.
  • All existing and new tests are passing (41 targeted Chrome tests, static analysis, and formatting passed locally).

@google-cla

google-cla Bot commented Nov 5, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Nov 5, 2026

@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 changes the type of logBuffer from List<String> to Iterable<String> in ChromiumLauncher, Chromium, and _SpawnResult, removing the call to toList() when instantiating _SpawnResult. Additionally, it adds a new test group 'Chromium crash diagnostics' in chrome_test.dart along with a _ControllableProcess helper class to verify Chromium logging, log eviction, process retries, and error filtering. There are no review comments, and no further feedback is provided.

@mehmetbahadirgungor
mehmetbahadirgungor marked this pull request as draft November 5, 2026 11:03
…stics

Fixes flutter#195823

During Chromium process launch, `_spawnChromiumProcess` collects stdout and
stderr into a rolling 200-line `ListQueue<String>` (`logBuffer`). When "DevTools listening"
was detected, `_spawnChromiumProcess` returned `logBuffer.toList()`, converting
the rolling buffer into a static snapshot of early startup output. As a result,
any diagnostic logs emitted after startup were lost when the process later
crashed unexpectedly with a non-zero exit code.

This change preserves the live `Iterable<String>` reference to the rolling
`ListQueue<String>` across `_SpawnResult` and `Chromium`, ensuring that crash
diagnostics capture the latest 200 log lines throughout the entire process
lifetime.
@mehmetbahadirgungor
mehmetbahadirgungor force-pushed the fix-chromium-crash-diagnostics branch from 24babca to 560eb6b Compare November 5, 2026 11:08
@mehmetbahadirgungor
mehmetbahadirgungor marked this pull request as ready for review November 5, 2026 15:17

@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 refactors chrome.dart by changing the type of logBuffer from List<String> to Iterable<String> in ChromiumLauncher, Chromium, and _SpawnResult, which removes an unnecessary list copy. It also adds a comprehensive set of unit tests in chrome_test.dart to verify Chromium crash diagnostics, including log eviction, process retries, D-Bus error filtering, and clean exits, using a new _ControllableProcess helper class. There are no review comments, and I have no feedback to provide.

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

Hi @mehmetbahadirgungor! Thanks for the fix! Left a few small comments to simplify the tests, otherwise this LGTM!

Comment on lines +1325 to +1342
expect(
testLogger.errorText,
contains('Chrome process PID 3579 exited unexpectedly with code 1.'),
);
expect(testLogger.errorText, contains('Last 200 lines of Chrome output:'));
// Older entries (first 50 lines and startup devtools listening) must be evicted.
for (var i = 0; i < 50; i++) {
expect(testLogger.errorText, isNot(contains('line-$i\n')));
}
expect(testLogger.errorText, isNot(contains('DevTools listening')));
// The most recent 200 lines must be present.
for (var i = 50; i < 250; i++) {
expect(testLogger.errorText, contains('[CHROME STDOUT]: line-$i\n'));
}
final int matchedLineCount = RegExp(r'\[CHROME STDOUT\]: line-\d+')
.allMatches(testLogger.errorText)
.length;
expect(matchedLineCount, 200);

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.

Nit: since testLogger.errorText is deterministic here, this can just be:

expect(
  testLogger.errorText,
  '''
Chrome process PID 3579 exited unexpectedly with code 1.
Last 200 lines of Chrome output:
${List<String>.generate(200, (int i) => '[CHROME STDOUT]: line-${i + 50}').join('\n')}
''',
);

Comment on lines +1394 to +1417
testWithoutContext('filters out Chromium D-Bus error lines from crash diagnostics', () async {
final process = _ControllableProcess(pid: 4444);
addChromeProcessCommand(process);

final Future<Chromium> launchFuture = chromeLauncher.launch('example_url', skipCheck: true);
process.emitStderr('DevTools listening on ws://127.0.0.1:12345/devtools/browser/abc');
final Chromium chrome = await launchFuture;

process.emitStderr('ERROR:dbus/bus.cc:123 Failed to connect to the bus');
process.emitStderr('Important error line after startup');
await pumpEventQueue();

process.crash();
await chrome.onExit;
await pumpEventQueue();

expect(
testLogger.errorText,
contains('Chrome process PID 4444 exited unexpectedly with code 1.'),
);
expect(testLogger.errorText, contains('[CHROME STDERR]: Important error line after startup'));
expect(testLogger.errorText, isNot(contains('ERROR:dbus/bus.cc')));
expect(testLogger.errorText, isNot(contains('Failed to connect to the bus')));
});

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.

Do we need a separate test for D-Bus filtering here? _isDbusError runs before addLog and is already covered by 'filters out Chromium D-Bus error lines from stderr logs' above.

Comment on lines +1446 to +1447
await chrome.close();
process.crash();

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.

chrome.close() already calls process.kill(), which completes _exitCompleter with exit code 15, so process.crash() here is a no-op and can be removed.

@bkonyi bkonyi added the CICD Run CI/CD label Nov 13, 2026

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

LGTM! We'll need one more review before we can land this.

@bkonyi
bkonyi requested a review from mdebbar November 13, 2026 17:27

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

LGTM! Thanks for contributing this fix!

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 16, 2026
@mdebbar mdebbar added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Nov 16, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 17, 2026
@auto-submit

auto-submit Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/196037, Failed to enqueue flutter/flutter/196037 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 20, 2026
@mdebbar mdebbar added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Nov 20, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 21, 2026
Merged via the queue into flutter:master with commit 177e69b Nov 21, 2026
20 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 21, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 21, 2026
flutter/flutter@b34b017...5423f94

2026-11-21 [email protected] Make an Impeller render target from a Vulkan backing store (flutter/flutter#193003)
2026-11-21 [email protected] Persist the vulkan shader cache on teardown (flutter/flutter#197017)
2026-11-21 [email protected] [flutter_tools] Preserve rolling log buffer for Chromium crash diagnostics (flutter/flutter#196037)
2026-11-21 [email protected] Roll Skia from 8845aecd8c53 to 39e0ad394168 (2 revisions) (flutter/flutter#197094)
2026-11-21 [email protected] Adds redirect for listen package in api.flutter.dev (flutter/flutter#197068)
2026-11-21 [email protected] Roll Dart SDK from c6857d58f0ec to fc86f5a42779 (1 revision) (flutter/flutter#197086)
2026-11-20 [email protected] iOS: Discard pending platform view disposals on reset (flutter/flutter#197026)
2026-11-20 [email protected] Tolerate a missing flutter/service_worker handler in the web first-frame notification (flutter/flutter#196329)
2026-11-20 [email protected] Roll Skia from 9aafbb357743 to 8845aecd8c53 (2 revisions) (flutter/flutter#197080)
2026-11-20 [email protected] Prevent crash in tessellator with extreme radii (flutter/flutter#196648)
2026-11-20 [email protected] Windows: in the flutter tool, always close the file handle in _download even when an HTTP request fails so that it is not left open and becomes undeletable (flutter/flutter#197061)
2026-11-20 [email protected] Roll Skia from b61640825c5b to 9aafbb357743 (7 revisions) (flutter/flutter#197066)
2026-11-20 [email protected] Swap dependabot reviewers (flutter/flutter#196995)
2026-11-20 [email protected] [iOS] Hide UIScrollEdgeEffect on FlutterSemanticsScrollView and scroll-to-top UIScrollView on iOS 26+ (flutter/flutter#195356)
2026-11-20 [email protected] [devicelab] Enable Vulkan GPU tracing by default on Android Impeller PerfTests (flutter/flutter#196822)
2026-11-20 [email protected] Roll Dart SDK from 3b5f45d812f8 to c6857d58f0ec (1 revision) (flutter/flutter#197063)
2026-11-20 [email protected] [flutter_tools] Delete flutter.version.json when switching channels (flutter/flutter#196943)
2026-11-20 [email protected] Update desktop TESTOWNERS (flutter/flutter#196930)
2026-11-20 [email protected] [web] Release CanvasKit WebGL contexts and surfaces when a view is removed (flutter/flutter#196816)
2026-11-20 [email protected] [Linux] Hide libunwind symbols in libflutter_linux_gtk.so (flutter/flutter#196451)
2026-11-20 [email protected] Roll Skia from a1edf5c2ea5c to b61640825c5b (1 revision) (flutter/flutter#197058)
2026-11-20 [email protected] [flutter_tools] Update --web-content-hash serving tip to cover assets and canvaskit (flutter/flutter#196908)
2026-11-20 [email protected] Send a semantics update when only the identifier changes (flutter/flutter#196460)
2026-11-20 [email protected] Roll Packages from 81b7c44 to 898818d (11 revisions) (flutter/flutter#197056)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flutter_tools] Chromium crash diagnostic prints only startup output instead of the last 200 lines

3 participants