Skip to content

Commit e4cfadc

Browse files
authored
[stable] [flutter_tools] Handle all DartDevelopmentServiceExceptions gracefully in resident web runner (#191323)
This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request) Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request. ### Issue Link: #191179 ### Impact Description: Unhandled `DartDevelopmentServiceException` during web debugging startup causes the Flutter CLI to crash. It emerged as a top crash signature in Flutter 3.47.0 telemetry. It impacts development (crashes the tool when browser exits prematurely or rejects handshake during startup). ### Changelog Description: [flutter/191179] When WebSocket upgrade fails during DDS startup on Web, handle the DartDevelopmentServiceException gracefully instead of crashing. ### Workaround: No workaround available; the tool crashes when the error occurs. ### Risk: What is the risk level of this cherry-pick? ### Test Coverage: Are you confident that your fix is well-tested by automated tests? ### Validation Steps: Run unit tests in `resident_web_runner_test.dart`, specifically the new test: "Does not crash if DDS fails to upgrade WebSocket during startup".
1 parent 6655482 commit e4cfadc

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

‎packages/flutter_tools/lib/src/isolated/resident_web_runner.dart‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,14 @@ class ResidentWebRunner extends ResidentRunner {
405405
stackTrace: stackTrace,
406406
);
407407
throwToolExit('Failed to connect to the web debug service.');
408-
} on DartDevelopmentServiceException catch (error) {
408+
} on DartDevelopmentServiceException catch (error, stackTrace) {
409409
// The application may have started shutting down before DDS was able to finish establishing
410410
// its connection to DWDS. Don't treat this as an unhandled exception.
411411
appFailedToStart();
412-
if (error.errorCode == DartDevelopmentServiceException.failedToStartError) {
413-
throwToolExit(kExitMessage);
412+
if (error.errorCode != DartDevelopmentServiceException.failedToStartError) {
413+
_logger.printError(error.message, stackTrace: stackTrace);
414414
}
415-
rethrow;
415+
throwToolExit(kExitMessage);
416416
} on Exception {
417417
appFailedToStart();
418418
rethrow;

‎packages/flutter_tools/test/general.shard/resident_web_runner_test.dart‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,36 @@ name: my_app
275275
'Does not crash if the application exits during DDS startup',
276276
() async {
277277
// Regression test for https://github.com/flutter/flutter/issues/178151
278-
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
278+
final logger = BufferLogger.test();
279+
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: logger);
279280
fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
280281
setupMocks();
281282
webDevFS.exception = DartDevelopmentServiceException.failedToStart();
282283

283284
await expectLater(residentWebRunner.run(), throwsToolExit());
285+
expect(logger.errorText, isEmpty);
286+
},
287+
overrides: <Type, Generator>{
288+
FileSystem: () => fileSystem,
289+
ProcessManager: () => processManager,
290+
Pub: ThrowingPub.new,
291+
},
292+
);
293+
294+
testUsingContext(
295+
'Does not crash if DDS fails to upgrade WebSocket during startup',
296+
() async {
297+
final logger = BufferLogger.test();
298+
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: logger);
299+
fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
300+
setupMocks();
301+
const errorMessage =
302+
'WebSocketChannelException: WebSocketException: Connection to '
303+
"'http://127.0.0.1:62932/9fVOXxsamo0=/ws#' was not upgraded to websocket";
304+
webDevFS.exception = DartDevelopmentServiceException.connectionIssue(errorMessage);
305+
306+
await expectLater(residentWebRunner.run(), throwsToolExit());
307+
expect(logger.errorText, contains(errorMessage));
284308
},
285309
overrides: <Type, Generator>{
286310
FileSystem: () => fileSystem,

0 commit comments

Comments
 (0)