Repository navigation
[flutter_tools] Preserve rolling log buffer for Chromium crash diagnostics - #196037
auto-submit[bot] merged 4 commits into
Conversation
|
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. |
There was a problem hiding this comment.
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.
…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.
24babca to
560eb6b
Compare
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Hi @mehmetbahadirgungor! Thanks for the fix! Left a few small comments to simplify the tests, otherwise this LGTM!
| 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); |
There was a problem hiding this comment.
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')}
''',
);| 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'))); | ||
| }); |
There was a problem hiding this comment.
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.
| await chrome.close(); | ||
| process.crash(); |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
LGTM! We'll need one more review before we can land this.
mdebbar
left a comment
There was a problem hiding this comment.
LGTM! Thanks for contributing this fix!
|
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/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
Fixes #195823
Description
During Chromium process launch in
ChromiumLauncher._spawnChromiumProcess, standard output and standard error streams are decoded and buffered into a rolling 200-lineListQueue<String>(logBuffer). When "DevTools listening" is detected onstderr,_spawnChromiumProcessunblocks and returns_SpawnResult(process, port, host, logBuffer.toList()).Because
logBuffer.toList()created a point-in-time snapshot of the queue into a separateListat early startup, subsequent log entries delivered by Chromium to the stream listeners after "DevTools listening" were not reflected inChromium._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 tologBufferacross_SpawnResultandChromium, ensuring that:Chromium._logBufferretains the latest lines received by the stdout and stderr stream listeners throughout the Chromium process lifetime.ListQueue<String>.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 viaclose()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
///).