Skip to content

Commit 8afcde1

Browse files
Swallow exceptions related to an already disposed service connection (#9265)
1 parent 7ac76bd commit 8afcde1

2 files changed

Lines changed: 38 additions & 20 deletions

File tree

packages/devtools_app/lib/src/screens/network/network_service.dart

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:vm_service/vm_service.dart';
66

7+
import '../../service/vm_service_wrapper.dart';
78
import '../../shared/globals.dart';
89
import '../../shared/primitives/utils.dart';
910
import '../../shared/utils/utils.dart';
@@ -68,23 +69,31 @@ class NetworkService {
6869
DebounceCancelledCallback? cancelledCallback,
6970
}) async {
7071
if (serviceConnection.serviceManager.service == null) return;
71-
final timestampObj = await serviceConnection.serviceManager.service!
72-
.getVMTimelineMicros();
73-
if (cancelledCallback?.call() ?? false) return;
72+
try {
73+
final timestampObj = await serviceConnection.serviceManager.service!
74+
.getVMTimelineMicros();
75+
if (cancelledCallback?.call() ?? false) return;
7476

75-
final timestamp = timestampObj.timestamp!;
76-
final sockets = await _refreshSockets();
77-
if (cancelledCallback?.call() ?? false) return;
78-
79-
networkController.lastSocketDataRefreshMicros = timestamp;
80-
List<HttpProfileRequest>? httpRequests;
81-
httpRequests = await _refreshHttpProfile();
82-
if (cancelledCallback?.call() ?? false) return;
83-
84-
networkController.processNetworkTraffic(
85-
sockets: sockets,
86-
httpRequests: httpRequests,
87-
);
77+
final timestamp = timestampObj.timestamp!;
78+
final sockets = await _refreshSockets();
79+
if (cancelledCallback?.call() ?? false) return;
80+
81+
networkController.lastSocketDataRefreshMicros = timestamp;
82+
List<HttpProfileRequest>? httpRequests;
83+
httpRequests = await _refreshHttpProfile();
84+
if (cancelledCallback?.call() ?? false) return;
85+
86+
networkController.processNetworkTraffic(
87+
sockets: sockets,
88+
httpRequests: httpRequests,
89+
);
90+
} on RPCError catch (e) {
91+
if (!e.isServiceDisposedError) {
92+
// Swallow exceptions related to trying to interact with an
93+
// already-disposed service connection. Otherwise, rethrow.
94+
rethrow;
95+
}
96+
}
8897
}
8998

9099
Future<List<HttpProfileRequest>> _refreshHttpProfile() async {

packages/devtools_app/lib/src/service/vm_service_wrapper.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,19 @@ class VmServiceWrapper extends VmService {
6969
// in https://github.com/flutter/devtools/pull/4119 as a workaround for
7070
// profiling the analysis server.
7171
Future<void> _initSupportedProtocols() async {
72-
final supportedProtocols = await getSupportedProtocols();
73-
final ddsProtocol = supportedProtocols.protocols?.firstWhereOrNull(
74-
(Protocol p) => p.protocolName?.caseInsensitiveEquals('DDS') ?? false,
75-
);
72+
Protocol? ddsProtocol;
73+
try {
74+
final supportedProtocols = await getSupportedProtocols();
75+
ddsProtocol = supportedProtocols.protocols?.firstWhereOrNull(
76+
(Protocol p) => p.protocolName?.caseInsensitiveEquals('DDS') ?? false,
77+
);
78+
} on RPCError catch (e) {
79+
if (!e.isServiceDisposedError) {
80+
// Swallow exceptions related to trying to interact with an
81+
// already-disposed service connection. Otherwise, rethrow.
82+
rethrow;
83+
}
84+
}
7685
_ddsSupported = ddsProtocol != null;
7786
_supportedProtocolsInitialized.complete();
7887
}

0 commit comments

Comments
 (0)