Skip to content

Commit 3a77ebd

Browse files
bkonyiCommit Queue
authored andcommitted
[ DDS ] Ignore method no found responses for streamCpuSamplesWithUserTag
DWDS does not implement streamCpuSamplesWithUserTag and DDS can invoke it without being prompted to by a client. This change gracefully handles the absence of this RPC. Related DWDS change: dart-lang/webdev#1889 Change-Id: Ic821f39caefd25044c2c4a8b34a8271879c7bd5f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279020 Reviewed-by: Elliott Brooks <[email protected]> Commit-Queue: Ben Konyi <[email protected]>
1 parent 3949fe9 commit 3a77ebd

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

pkg/dds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# 2.7.1
66
- Updated `vm_service` version to >=9.0.0 <11.0.0.
77
- Simplified the DevTools URI composed by DDS.
8+
- Fix issue where DDS was invoking an unimplemented RPC against a non-VM target.
89

910
# 2.7.0
1011
- Added `DartDevelopmentService.setExternalDevToolsUri(Uri uri)`, adding support for registering an external DevTools server with DDS.

pkg/dds/lib/src/dds_impl.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import 'devtools/handler.dart';
2727
import 'expression_evaluator.dart';
2828
import 'isolate_manager.dart';
2929
import 'package_uri_converter.dart';
30+
import 'rpc_error_codes.dart';
3031
import 'stream_manager.dart';
3132

3233
@visibleForTesting
@@ -483,3 +484,18 @@ class DartDevelopmentServiceImpl implements DartDevelopmentService {
483484
late WebSocketChannel _vmServiceSocket;
484485
late HttpServer _server;
485486
}
487+
488+
extension PeerExtension on json_rpc.Peer {
489+
Future<dynamic> sendRequestAndIgnoreMethodNotFound(
490+
String method, [
491+
dynamic parameters,
492+
]) async {
493+
try {
494+
await sendRequest(method, parameters);
495+
} on json_rpc.RpcException catch (e) {
496+
if (e.code != RpcErrorCodes.kMethodNotFound) {
497+
rethrow;
498+
}
499+
}
500+
}
501+
}

pkg/dds/lib/src/isolate_manager.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class IsolateManager {
242242
}
243243
}
244244
if (dds.cachedUserTags.isNotEmpty) {
245-
await dds.vmServiceClient.sendRequest(
245+
await dds.vmServiceClient.sendRequestAndIgnoreMethodNotFound(
246246
'streamCpuSamplesWithUserTag',
247247
{
248248
'userTags': dds.cachedUserTags,

pkg/dds/lib/src/stream_manager.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,13 @@ class StreamManager {
238238
if (streamListeners[stream]!.contains(client)) {
239239
throw kStreamAlreadySubscribedException;
240240
} else if (!streamNewlySubscribed && includePrivates != null) {
241-
try {
242-
await dds.vmServiceClient.sendRequest(
243-
'_setStreamIncludePrivateMembers',
244-
{'streamId': stream, 'includePrivateMembers': includePrivates});
245-
} on json_rpc.RpcException catch (e) {
246-
// This private RPC might not be present. If it's not, we're communicating with an older
247-
// VM that doesn't support filtering private members, so they will always be included in
248-
// responses. Handle the method not found exception so the streamListen call doesn't
249-
// fail for older VMs.
250-
if (e.code != RpcErrorCodes.kMethodNotFound) {
251-
rethrow;
252-
}
253-
}
241+
// This private RPC might not be present. If it's not, we're communicating with an older
242+
// VM that doesn't support filtering private members, so they will always be included in
243+
// responses. Handle the method not found exception so the streamListen call doesn't
244+
// fail for older VMs.
245+
await dds.vmServiceClient.sendRequestAndIgnoreMethodNotFound(
246+
'_setStreamIncludePrivateMembers',
247+
{'streamId': stream, 'includePrivateMembers': includePrivates});
254248
}
255249
if (client != null) {
256250
streamListeners[stream]!.add(client);
@@ -352,9 +346,12 @@ class StreamManager {
352346
_profilerUserTagSubscriptions.remove(subscribedTag);
353347
}
354348
}
355-
await dds.vmServiceClient.sendRequest('streamCpuSamplesWithUserTag', {
356-
'userTags': _profilerUserTagSubscriptions.toList(),
357-
});
349+
await dds.vmServiceClient.sendRequestAndIgnoreMethodNotFound(
350+
'streamCpuSamplesWithUserTag',
351+
{
352+
'userTags': _profilerUserTagSubscriptions.toList(),
353+
},
354+
);
358355
});
359356
}
360357

0 commit comments

Comments
 (0)