Repository navigation
[CP-stable][flutter_tools] Safely handle non-JSON messages in test stream parsers - #192419
Conversation
flutter#192089) When communicating with remote test runners or browsers over test streams or WebSockets, unhandled non-JSON strings (such as dynamic library loading errors or missing snapshot warnings) caused `_ChunkedJsonParser` to throw an unhandled `FormatException` at character 1, crashing the tool. This changes `pipeHarnessToRemote` in `flutter_platform.dart` and `BrowserManager` in `flutter_web_platform.dart` to intercept non-JSON payloads, log warnings and traces, and ignore invalid frames rather than crashing the tool process. Fixes flutter#191898 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] 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). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
|
@bkonyi please fill out the PR description above, afterwards the release team will review this request. |
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
There was a problem hiding this comment.
Code Review
This pull request updates the test platform and web platform implementations to handle FormatException during JSON decoding of streams from the test runner and browser WebSocket, logging a warning and trace message instead of failing. It also exposes pipeHarnessToRemote for testing and adds a unit test to verify this behavior. I have no feedback to provide.
|
@bkonyi. Spoke too soon - could you add a secondary reviewer here as well? |
|
autosubmit label was removed for flutter/flutter/192419, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
Hi @bkonyi, I think there may be a dependency that also needs to be cherry picked. |
…logging When cherry-picking flutter#192089 to the stable release candidate branch `flutter-3.47-candidate.0`, `BrowserManager` in `flutter_web_platform.dart` referenced `_logger` without `_logger` being defined on `BrowserManager` (which was added on `master` in a later Chrome roll PR). This passes `_logger` from `FlutterWebPlatform` through `BrowserManager.start` and stores it on `BrowserManager` so that unexpected non-JSON messages can be logged as intended.
|
Should be fixed now! |
9584c67
into
flutter:flutter-3.47-candidate.0
This pull request is created by automatic cherry pick workflow
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.
Issue Link:
#191898
Impact Description:
Top crash in Flutter 3.47.1 accounting for 245 crashes (11.7% share of top crashes). When a test runner process or browser socket dumps unformatted non-JSON error output (such as dynamic library loading errors or missing snapshot warnings) directly onto the test communication stream or WebSocket,
_ChunkedJsonParserthrows an unhandledFormatException: Unexpected character (at character 1), terminating theflutter testCLI process.Changelog Description:
[flutter/191898] When remote test processes emit plain-text error output on all platforms, prevent flutter_tools from crashing with an unhandled FormatException.
Workaround:
None. Any test execution where a child runner or socket prints plain text instead of JSON fatal crashes the test runner CLI.
Risk:
Test Coverage:
Validation Steps:
Run
flutter test test/general.shard/flutter_platform_test.dartandflutter test test/commands.shard/hermetic/flutter_web_platform_test.dart.Specifically,
pipeHarnessToRemote safely ignores non-JSON string and logs warningvalidates that plain text received over the stream logs a warning/trace without crashing the process, and subsequent valid JSON packets are processed normally.