From 3b6aeb43fa722df34ae652ba4f2672a09a649225 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Wed, 12 Aug 2020 16:17:04 +0000 Subject: [PATCH] Handle StateError for closed serviceClient In https://github.com/dart-lang/json_rpc_2/pull/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 Commit-Queue: Ben Konyi Reviewed-by: Ben Konyi --- pkg/dds/CHANGELOG.md | 4 ++++ pkg/dds/lib/src/client.dart | 6 +++++- pkg/dds/pubspec.yaml | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/dds/CHANGELOG.md b/pkg/dds/CHANGELOG.md index 77142a4d075..52b7282fd87 100644 --- a/pkg/dds/CHANGELOG.md +++ b/pkg/dds/CHANGELOG.md @@ -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 diff --git a/pkg/dds/lib/src/client.dart b/pkg/dds/lib/src/client.dart index 3d796fc52ab..79e4233bd91 100644 --- a/pkg/dds/lib/src/client.dart +++ b/pkg/dds/lib/src/client.dart @@ -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( diff --git a/pkg/dds/pubspec.yaml b/pkg/dds/pubspec.yaml index a4bccc8f107..3a8364c46f5 100644 --- a/pkg/dds/pubspec.yaml +++ b/pkg/dds/pubspec.yaml @@ -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