Skip to content

Commit

Permalink
[package:vm_service] Include stack traces with 'Service connection di…
Browse files Browse the repository at this point in the history
…sposed' RPCErrors

TEST=pkg/vm_service/test/regress_55559_test.dart

Issue: #56491
Change-Id: I584cbc0827a1a074d28840819cc572beba5f2854
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381060
Reviewed-by: Ben Konyi <[email protected]>
Commit-Queue: Derek Xu <[email protected]>
  • Loading branch information
derekxu16 authored and Commit Queue committed Aug 16, 2024
1 parent e8a049f commit 354084c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
4 changes: 4 additions & 0 deletions pkg/vm_service/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 14.2.5
- Include a stack trace in the RPCError that is thrown when an attempt is made
to invoke an RPC using a `VmService` instance that has been disposed.

## 14.2.4
- Improved deserialization performance by utilizing a combination of `Utf8Decoder` and
`JsonDecoder` to avoid extra type conversions.
Expand Down
2 changes: 1 addition & 1 deletion pkg/vm_service/lib/src/vm_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ class VmService {
_disposed = true;
await _streamSub.cancel();
_outstandingRequests.forEach((id, request) {
request._completer.completeError(RPCError(
request.completeError(RPCError(
request.method,
RPCErrorKind.kServerError.code,
'Service connection disposed',
Expand Down
2 changes: 1 addition & 1 deletion pkg/vm_service/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: vm_service
version: 14.2.4
version: 14.2.5
description: >-
A library to communicate with a service implementing the Dart VM
service protocol.
Expand Down
23 changes: 20 additions & 3 deletions pkg/vm_service/test/regress_55559_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ void main() {
final vm = await service.getVM();
final isolate = vm.isolates!.first;
final errorCompleter = Completer<RPCError>();
final stackTraceCompleter = Completer<StackTrace>();
unawaited(
service.getIsolate(isolate.id!).then(
(_) => fail('Future should throw'),
onError: (e) => errorCompleter.complete(e),
),
(_) => fail('Future should throw'),
onError: (e, st) {
errorCompleter.complete(e);
stackTraceCompleter.complete(st);
},
),
);
killProcess();

Expand All @@ -72,6 +76,19 @@ void main() {
final error = await errorCompleter.future;
expect(error.code, RPCErrorKind.kServerError.code);
expect(error.message, 'Service connection disposed');

// Confirm that a stack trace was included and that it contains the actual
// invocation path.
final stackTrace = await stackTraceCompleter.future;
final stack = stackTrace.toString().split('\n');
expect(
stack.where((e) => e.contains('VmService.getIsolate')).length,
1,
);
expect(
stack.where((e) => e.contains('test/regress_55559_test.dart')).length,
1,
);
},
);
}
2 changes: 1 addition & 1 deletion pkg/vm_service/tool/dart/generate_dart_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export 'snapshot_graph.dart' show HeapSnapshotClass,
_disposed = true;
await _streamSub.cancel();
_outstandingRequests.forEach((id, request) {
request._completer.completeError(RPCError(
request.completeError(RPCError(
request.method,
RPCErrorKind.kServerError.code,
'Service connection disposed',
Expand Down

0 comments on commit 354084c

Please sign in to comment.