Handle "Service connection disposed" error from VmService disconnecting while requests are outstanding (#153714)
Fixes umbrella issue https://github.com/flutter/flutter/issues/153471, including its children: https://github.com/flutter/flutter/issues/153472, https://github.com/flutter/flutter/issues/153473, and https://github.com/flutter/flutter/issues/153474. The VM service can be disposed at any time during requests (e.g. the user closes the app or stops debugging in VSCode)[^1].a479f91e80anda7d8707a59updated package:vm_service to throw new `RPCError`s when the service disconnects while requests are inflight. Therefore, we need to handle these exceptions in the tool. See umbrella issue for more details. I plan on cherry-picking this change to the stable channel. [^1]: https://github.com/flutter/flutter/issues/153471#issuecomment-2296294221
This commit is contained in:
@@ -1125,6 +1125,45 @@ void main() {
|
||||
DeviceManager: () => testDeviceManager,
|
||||
});
|
||||
|
||||
testUsingContext('Catches "Service connection disposed" error', () async {
|
||||
final FakeAndroidDevice device = FakeAndroidDevice(id: '1')
|
||||
..portForwarder = const NoOpDevicePortForwarder()
|
||||
..onGetLogReader = () => NoOpDeviceLogReader('test');
|
||||
final FakeHotRunner hotRunner = FakeHotRunner();
|
||||
final FakeHotRunnerFactory hotRunnerFactory = FakeHotRunnerFactory()
|
||||
..hotRunner = hotRunner;
|
||||
hotRunner.onAttach = (
|
||||
Completer<DebugConnectionInfo>? connectionInfoCompleter,
|
||||
Completer<void>? appStartedCompleter,
|
||||
bool allowExistingDdsInstance,
|
||||
bool enableDevTools,
|
||||
) async {
|
||||
await null;
|
||||
throw vm_service.RPCError('flutter._listViews', RPCErrorCodes.kServerError, 'Service connection disposed');
|
||||
};
|
||||
|
||||
testDeviceManager.devices = <Device>[device];
|
||||
testFileSystem.file('lib/main.dart').createSync();
|
||||
|
||||
final AttachCommand command = AttachCommand(
|
||||
hotRunnerFactory: hotRunnerFactory,
|
||||
stdio: stdio,
|
||||
logger: logger,
|
||||
terminal: terminal,
|
||||
signals: signals,
|
||||
platform: platform,
|
||||
processInfo: processInfo,
|
||||
fileSystem: testFileSystem,
|
||||
);
|
||||
await expectLater(createTestCommandRunner(command).run(<String>[
|
||||
'attach',
|
||||
]), throwsToolExit(message: 'Lost connection to device.'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => testFileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
DeviceManager: () => testDeviceManager,
|
||||
});
|
||||
|
||||
testUsingContext('Does not catch generic RPC error', () async {
|
||||
final FakeAndroidDevice device = FakeAndroidDevice(id: '1')
|
||||
..portForwarder = const NoOpDevicePortForwarder()
|
||||
|
||||
Reference in New Issue
Block a user