Unverified Commit 6dbdccf7 authored by Andrew Davies's avatar Andrew Davies Committed by GitHub

[frdb] Updates `invokeRpc` method and VM connect. (#17819)

This fixes a runtime error triggered when calling `invokeRpc`:
```
type 'Future<dynamic>' is not a subtype of type 'Future<Map<String, dynamic>>'
```

Also adds a log message for why connections are failing, as well as a
default timeout when attempting to connect to a websocket.
parent 9471e4e2
...@@ -38,7 +38,8 @@ Future<json_rpc.Peer> _waitAndConnect(Uri uri) async { ...@@ -38,7 +38,8 @@ Future<json_rpc.Peer> _waitAndConnect(Uri uri) async {
WebSocket socket; WebSocket socket;
json_rpc.Peer peer; json_rpc.Peer peer;
try { 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(); peer = new json_rpc.Peer(new IOWebSocketChannel(socket).cast())..listen();
return peer; return peer;
} on HttpException catch (e) { } on HttpException catch (e) {
...@@ -48,6 +49,7 @@ Future<json_rpc.Peer> _waitAndConnect(Uri uri) async { ...@@ -48,6 +49,7 @@ Future<json_rpc.Peer> _waitAndConnect(Uri uri) async {
await socket?.close(); await socket?.close();
rethrow; rethrow;
} catch (e) { } catch (e) {
_log.fine('Dart VM connection failed $e: ${e.message}');
// Other unknown errors will be handled with reconnects. // Other unknown errors will be handled with reconnects.
await peer?.close(); await peer?.close();
await socket?.close(); await socket?.close();
...@@ -141,19 +143,15 @@ class DartVm { ...@@ -141,19 +143,15 @@ class DartVm {
Map<String, dynamic> params, Map<String, dynamic> params,
Duration timeout = _kRpcTimeout, Duration timeout = _kRpcTimeout,
}) async { }) async {
final Future<Map<String, dynamic>> future = _peer.sendRequest( final Map<String, dynamic> result = await _peer
function, .sendRequest(function, params ?? <String, dynamic>{})
params ?? <String, dynamic>{}, .timeout(timeout, onTimeout: () {
);
if (timeout == null) {
return future;
}
return future.timeout(timeout, onTimeout: () {
throw new TimeoutException( throw new TimeoutException(
'Peer connection timed out during RPC call', 'Peer connection timed out during RPC call',
timeout, timeout,
); );
}); });
return result;
} }
/// Returns a list of [FlutterView] objects running across all Dart VM's. /// Returns a list of [FlutterView] objects running across all Dart VM's.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment