From 6d4b0abfa8bfd6b2ba3ff01e9cfde7d7813e9c86 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 14 May 2019 16:04:04 -0700 Subject: [PATCH] Ignore some JSON RPC errors (#32710) --- .../flutter_driver/lib/src/driver/driver.dart | 28 +++++++++++++++++++ .../lib/src/dart/dart_vm.dart | 28 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/packages/flutter_driver/lib/src/driver/driver.dart b/packages/flutter_driver/lib/src/driver/driver.dart index 9fd3771002..31010c4cd8 100644 --- a/packages/flutter_driver/lib/src/driver/driver.dart +++ b/packages/flutter_driver/lib/src/driver/driver.dart @@ -956,7 +956,35 @@ void restoreVmServiceConnectFunction() { vmServiceConnectFunction = _waitAndConnect; } +/// The JSON RPC 2 spec says that a notification from a client must not respond +/// to the client. It's possible the client sent a notification as a "ping", but +/// the service isn't set up yet to respond. +/// +/// For example, if the client sends a notification message to the server for +/// 'streamNotify', but the server has not finished loading, it will throw an +/// exception. Since the message is a notification, the server follows the +/// specification and does not send a response back, but is left with an +/// unhandled exception. That exception is safe for us to ignore - the client +/// is signaling that it will try again later if it doesn't get what it wants +/// here by sending a notification. +// This may be ignoring too many exceptions. It would be best to rewrite +// the client code to not use notifications so that it gets error replies back +// and can decide what to do from there. +// TODO(dnfield): https://github.com/flutter/flutter/issues/31813 +bool _ignoreRpcError(dynamic error) { + if (error is rpc.RpcException) { + final rpc.RpcException exception = error; + return exception.data == null || exception.data['id'] == null; + } else if (error is String && error.startsWith('JSON-RPC error -32601')) { + return true; + } + return false; +} + void _unhandledJsonRpcError(dynamic error, dynamic stack) { + if (_ignoreRpcError(error)) { + return; + } _log.trace('Unhandled RPC error:\n$error\n$stack'); // TODO(dnfield): https://github.com/flutter/flutter/issues/31813 // assert(false); 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 410d6f8251..bc18e3264d 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 @@ -31,8 +31,36 @@ typedef RpcPeerConnectionFunction = Future Function( /// custom connection function is needed. RpcPeerConnectionFunction fuchsiaVmServiceConnectionFunction = _waitAndConnect; +/// The JSON RPC 2 spec says that a notification from a client must not respond +/// to the client. It's possible the client sent a notification as a "ping", but +/// the service isn't set up yet to respond. +/// +/// For example, if the client sends a notification message to the server for +/// 'streamNotify', but the server has not finished loading, it will throw an +/// exception. Since the message is a notification, the server follows the +/// specification and does not send a response back, but is left with an +/// unhandled exception. That exception is safe for us to ignore - the client +/// is signaling that it will try again later if it doesn't get what it wants +/// here by sending a notification. +// This may be ignoring too many exceptions. It would be best to rewrite +// the client code to not use notifications so that it gets error replies back +// and can decide what to do from there. +// TODO(dnfield): https://github.com/flutter/flutter/issues/31813 +bool _ignoreRpcError(dynamic error) { + if (error is json_rpc.RpcException) { + final json_rpc.RpcException exception = error; + return exception.data == null || exception.data['id'] == null; + } else if (error is String && error.startsWith('JSON-RPC error -32601')) { + return true; + } + return false; +} + void _unhandledJsonRpcError(dynamic error, dynamic stack) { + if (_ignoreRpcError(error)) { + return; + } _log.fine('Error in internalimplementation of JSON RPC.\n$error\n$stack'); }