Repository navigation
[flutter_tools] Guard socket streams and done futures against socket reset errors - #192941
Merged
Merged
Conversation
…reset errors
When remote peers abruptly terminate or reset network connections, POSIX event
handlers (such as epoll) trigger low-level socket reset errors
(`SocketException: Error event raised in event handler : error condition has been reset, port = 0`)
via `_NativeSocket.multiplex`.
If these socket error events occur on streams or sink `done` futures that lack
error handlers, or when adding to/closing sinks in an error state, the unhandled
exception escapes into the Zone and causes Flutter tool crashes.
This change:
- Introduces `FutureErrorHandling<T>` in `packages/flutter_tools/lib/src/base/common.dart` to provide a reusable `.handleError(...)` extension on `Future` for background futures without requiring empty `(_) {}` callbacks.
- Guards `createVmServiceDelegate` channel streams, sink `done` futures, and sink operations against `SocketException`.
- Guards `DaemonStreams.fromSocket`, `DaemonStreams.connect`, and daemon server `socket.done` and `socket.addStream` futures.
- Adds `onError` handling to `ProxiedPortForwarder` forwarded socket streams.
- Adds `onError` handling to `ResidentRunner` log streams.
- Adds error handling to `AndroidConsole` socket `done` future on connect and destroy.
- Adds unit tests for `FutureErrorHandling.handleError` (including `test` predicate filtering) and regression tests verifying that socket stream and done future errors do not crash the tool.
Fixes flutter#192935
…atch StateError on VM service sink - Update `FutureErrorHandling.handleError` to rethrow unmatched errors via `Error.throwWithStackTrace` when `test` evaluates to `false`. - Catch `Object` (covering both `Exception` and `StateError`) around `channel.add` and `channel.close` in `createVmServiceDelegate`. - Add unit tests verifying unmatched error rethrowing and synchronous `StateError` handling.
…tion, and injected logger - Replace `dynamic` with `Object?` on VM service channel streams and test `FakeWebSocket` signatures. - Move collection generic type parameters to the RHS list literals in `daemon_test.dart` and `vmservice_test.dart`. - Convert `DaemonStreams.fromSocket` to a `factory` constructor delegating to `DaemonStreams(socket, socket, logger: logger)`. - Inject `Logger` into `FlutterDevice` (`_logger`) and use `_logger.printTrace` instead of `globals.printTrace`. - Use `_` wildcards for unused callback parameters and use `.handleError` extension in `vmservice_test.dart`.
…ogger fallback - Use nullable `this._logger` initializer on `FlutterDevice` and pass `logger: logger` from `FlutterDevice.create`. - Call `_logger?.printTrace` in `startEchoingDeviceLog` to avoid introducing any new `globals.logger` references.
…tch clauses, and clean up test fakes - Override `done` on fake AndroidConsole sockets in `android_device_test.dart` and add a unit test for `socket.done` completing with `SocketException`. - Revert `FlutterDevice` constructor signature in `resident_runner.dart` and use `globals.printTrace` in `startEchoingDeviceLog`. - Narrow `on Object catch` in `createVmServiceDelegate` to `on Exception` and `on StateError`, and close the channel when a write fails. - Remove unused fields and methods from `FakeSocket` in `daemon_test.dart` and `FakeWebSocket` in `vmservice_test.dart`.
…done fields on fake sockets - Omit unused `catch (_)` in `handleWriteError` and extract `logCloseError` helper in `disposeHandler` in `vmservice.dart`. - Use `@override final Future<void> done` fields on fake Android console sockets in `android_device_test.dart`.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a custom FutureErrorHandling extension on Future to handle errors on background sink and socket completion futures, applying it across several files and adding corresponding unit tests. The code review suggests removing this custom extension entirely to avoid unnecessary complexity and potential confusion, recommending instead the use of standard Dart APIs like catchError or then().catchError() at the call sites, along with removing the associated unit tests and imports.
…orHandling.handleError - Explain in `FutureErrorHandling.handleError`'s doc comment why `Future.then` is used instead of `Future.catchError` or `Future.onError` (`AvoidFutureCatchError` custom analyzer rule in `dev/bots/custom_rules/avoid_future_catcherror.dart`, flutter#130662, dart-lang/sdk#51248).
camsim99
previously approved these changes
Sep 28, 2026
camsim99
left a comment
Contributor
There was a problem hiding this comment.
Looks reasonable to me!
camsim99
approved these changes
Sep 29, 2026
Contributor
Author
|
Thanks @camsim99! 😁 |
This was referenced Sep 30, 2026
auto-submit Bot
pushed a commit
to flutter/packages
that referenced
this pull request
Sep 30, 2026
flutter/flutter@55b8f88...d649d2b 2026-09-30 43054281+camsim99@users.noreply.github.com [Android] Update the CLI to reject passing engine configuration flags with a prebuilt binary in release mode (flutter/flutter#190870) 2026-09-30 engine-flutter-autoroll@skia.org Roll Skia from af1e8b356dd1 to c7b323126bf0 (1 revision) (flutter/flutter#193569) 2026-09-30 zhongliu88889@gmail.com [web] Respect text affinity in getLineBoundary at a soft wrap (flutter/flutter#192664) 2026-09-30 bkonyi@google.com [tool] Migrate TestCommand and platform runner to modular dependency injection (flutter/flutter#190789) 2026-09-30 engine-flutter-autoroll@skia.org Roll Skia from 3a20a0464d25 to af1e8b356dd1 (1 revision) (flutter/flutter#193564) 2026-09-30 engine-flutter-autoroll@skia.org Roll Skia from 554ef62d11a9 to 3a20a0464d25 (6 revisions) (flutter/flutter#193556) 2026-09-30 116356835+AbdeMohlbi@users.noreply.github.com Use null aware elements in `platform_views.dart` (flutter/flutter#193214) 2026-09-30 116356835+AbdeMohlbi@users.noreply.github.com Replace deprecated `withOpacity` in `flutter_logo.dart` (flutter/flutter#192583) 2026-09-30 engine-flutter-autoroll@skia.org Roll Skia from f441ca223b2b to 554ef62d11a9 (72 revisions) (flutter/flutter#193548) 2026-09-30 joel.winarske@linux.com Fix StrcmpFixed matching prefixes in the Vulkan embedder tests (flutter/flutter#192999) 2026-09-30 jesswon@google.com Update Engine to test Android 17 AVD (flutter/flutter#193239) 2026-09-29 joel.winarske@linux.com Give the Vulkan test context the extensions Impeller requires (flutter/flutter#193002) 2026-09-29 55765052+MohanadAbdallah-mv@users.noreply.github.com Rename "subtext" to "supportingTextPadding" in `FormField`'s documentation (flutter/flutter#183582) 2026-09-29 markzipan@google.com Set --no-js-strongly-connected-components for DDC compiles by default (flutter/flutter#193485) 2026-09-29 jesswon@google.com Split pre-AGP 8.3 module AAR test into a Java 17 pinned target (flutter/flutter#193467) 2026-09-29 32538273+ValentinVignal@users.noreply.github.com Remove no-shuffle from gen_defaults_test (flutter/flutter#192280) 2026-09-29 katelovett@google.com Update guidance on bumping Dart (flutter/flutter#193131) 2026-09-29 dbebawy@users.noreply.github.com Remove vestigial `download_jdk` gclient var (flutter/flutter#188571) 2026-09-29 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#193522) 2026-09-29 bkonyi@google.com [flutter_tools] Lazily initialize AndroidSdk platform and build-tools discovery (flutter/flutter#191972) 2026-09-29 bkonyi@google.com [tool] Migrate Web build subcommands and toolchain to modular dependency injection (flutter/flutter#190783) 2026-09-29 matt.boetger@gmail.com Pin androidx.test dependencies in integration_test (flutter/flutter#193316) 2026-09-29 Deil.Christoph@gmail.com [flutter_tools] Include flutter.js.map in web builds (flutter/flutter#192257) 2026-09-29 Rusino@users.noreply.github.com [WebParagraph] Fixing edge cases for wrapping text (with newlines) (flutter/flutter#189858) 2026-09-29 ryjohn@google.com Bump customer testing version for flutter/devtools update (flutter/flutter#193511) 2026-09-29 engine-flutter-autoroll@skia.org Roll Packages from ba0364a to 3c6ce59 (14 revisions) (flutter/flutter#193507) 2026-09-29 bkonyi@google.com [flutter_tools] Guard socket streams and done futures against socket reset errors (flutter/flutter#192941) 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 quncheng@google.com,stuartmorgan@google.com 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When remote peers abruptly terminate or reset network connections, POSIX event handlers (such as epoll) trigger low-level socket reset errors (
SocketException: Error event raised in event handler : error condition has been reset, port = 0) via_NativeSocket.multiplex.If these socket error events occur on streams or sink
donefutures that lack error handlers, or when adding to/closing sinks in an error state, the unhandled exception escapes into the Zone and causes Flutter tool crashes.This change:
FutureErrorHandling<T>inpackages/flutter_tools/lib/src/base/common.dartto provide a reusable.handleError(...)extension onFuturefor background futures without requiring empty(_) {}callbacks.createVmServiceDelegatechannel streams, sinkdonefutures, and sink operations againstSocketException.DaemonStreams.fromSocket,DaemonStreams.connect, and daemon serversocket.doneandsocket.addStreamfutures.onErrorhandling toProxiedPortForwarderforwarded socket streams.onErrorhandling toResidentRunnerlog streams.AndroidConsolesocketdonefuture on connect and destroy.FutureErrorHandling.handleError(includingtestpredicate filtering) and regression tests verifying that socket stream and done future errors do not crash the tool.Fixes #192935
Pre-launch Checklist
///).