Skip to content

Commit

Permalink
Handle StateError for closed serviceClient
Browse files Browse the repository at this point in the history
In dart-lang/json_rpc_2#52 the `Peer` class was
fixed to behave like a `Client` when the connection is closed with
outstanding requests.

`package:dds` was previously relying on having the futures never
complete to send the `serviceDisappeared` code when the client was
closed with outstanding requests. Check also for the `StateError` that
would result from outstanding requests and translate them to
`serviceDisappeared`.

Change-Id: I2d3f186d1d52d34082b7adf5bf962e22df74015b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158220
Auto-Submit: Nate Bosch <nbosch@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
  • Loading branch information
natebosch authored and commit-bot@chromium.org committed Aug 12, 2020
1 parent d16bc3a commit 3b6aeb4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/dds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.3.2-dev

- Fix handling of requests that are outstanding when a client channel is closed.

# 1.3.1

- Fixed issue where an exception could be thrown during startup if the target
Expand Down
6 changes: 5 additions & 1 deletion pkg/dds/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ class _DartDevelopmentServiceClient {
return await Future.any(
[
// Forward the request to the service client or...
serviceClient.sendRequest(method, parameters.asMap),
serviceClient.sendRequest(method, parameters.asMap).catchError((_) {
throw _RpcErrorCodes.buildRpcException(
_RpcErrorCodes.kServiceDisappeared,
);
}, test: (error) => error is StateError),
// if the service client closes, return an error response.
serviceClient._clientPeer.done.then(
(_) => throw _RpcErrorCodes.buildRpcException(
Expand Down
2 changes: 1 addition & 1 deletion pkg/dds/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: >-
A library used to spawn the Dart Developer Service, used to communicate with
a Dart VM Service instance.
version: 1.3.1
version: 1.3.2-dev

homepage: https://github.com/dart-lang/sdk/tree/master/pkg/dds

Expand Down

0 comments on commit 3b6aeb4

Please sign in to comment.