Unverified Commit 6d4b0abf authored by Dan Field's avatar Dan Field Committed by GitHub

Ignore some JSON RPC errors (#32710)

parent 5f982604
......@@ -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);
......
......@@ -31,8 +31,36 @@ typedef RpcPeerConnectionFunction = Future<json_rpc.Peer> 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');
}
......
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