From 6dbdccf7f5f727745e97bf910f98fd085902bb51 Mon Sep 17 00:00:00 2001 From: Andrew Davies Date: Tue, 22 May 2018 15:49:47 -0700 Subject: [PATCH] [frdb] Updates `invokeRpc` method and VM connect. (#17819) This fixes a runtime error triggered when calling `invokeRpc`: ``` type 'Future' is not a subtype of type 'Future>' ``` Also adds a log message for why connections are failing, as well as a default timeout when attempting to connect to a websocket. --- .../lib/src/dart/dart_vm.dart | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart b/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart index 93a88a62602..98df7e63365 100644 --- a/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart +++ b/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart @@ -38,7 +38,8 @@ Future _waitAndConnect(Uri uri) async { WebSocket socket; json_rpc.Peer peer; try { - socket = await WebSocket.connect(uri.toString()); + socket = + await WebSocket.connect(uri.toString()).timeout(_kConnectTimeout); peer = new json_rpc.Peer(new IOWebSocketChannel(socket).cast())..listen(); return peer; } on HttpException catch (e) { @@ -48,6 +49,7 @@ Future _waitAndConnect(Uri uri) async { await socket?.close(); rethrow; } catch (e) { + _log.fine('Dart VM connection failed $e: ${e.message}'); // Other unknown errors will be handled with reconnects. await peer?.close(); await socket?.close(); @@ -141,19 +143,15 @@ class DartVm { Map params, Duration timeout = _kRpcTimeout, }) async { - final Future> future = _peer.sendRequest( - function, - params ?? {}, - ); - if (timeout == null) { - return future; - } - return future.timeout(timeout, onTimeout: () { + final Map result = await _peer + .sendRequest(function, params ?? {}) + .timeout(timeout, onTimeout: () { throw new TimeoutException( 'Peer connection timed out during RPC call', timeout, ); }); + return result; } /// Returns a list of [FlutterView] objects running across all Dart VM's.