diff --git a/common/geth/handle_error.go b/common/geth/handle_error.go index 1998df26a0..c75942c45c 100644 --- a/common/geth/handle_error.go +++ b/common/geth/handle_error.go @@ -25,7 +25,7 @@ const ( func (f *FailoverController) handleHttpError(httpRespError rpc.HTTPError) (NextEndpoint, ImmediateAction) { sc := httpRespError.StatusCode // Default to rotation the current RPC, because it allows a higher chance to get the query completed. - f.Logger.Info("[HTTP Response Error]", "Status Code", sc, "Error", httpRespError) + f.Logger.Info("[HTTP Response Error]", "Curr Rpc Fault", f.numberRpcFault, "Status Code", sc, "Error", httpRespError) if sc >= 200 && sc < 300 { // 2xx error, however it should not be reachable @@ -51,7 +51,8 @@ func (f *FailoverController) handleHttpError(httpRespError rpc.HTTPError) (NextE // If the error is http, non2xx error would generate HTTP error, https://github.com/ethereum/go-ethereum/blob/master/rpc/http.go#L233 // but a 2xx http response could contain JSON RPC error, https://github.com/ethereum/go-ethereum/blob/master/rpc/http.go#L181 // If the error is Websocket or IPC, we only look for JSON error, https://github.com/ethereum/go-ethereum/blob/master/rpc/json.go#L67 - +// +// This function is protected by mutex from the outside func (f *FailoverController) handleError(err error) (NextEndpoint, ImmediateAction) { var httpRespError rpc.HTTPError @@ -65,15 +66,15 @@ func (f *FailoverController) handleError(err error) (NextEndpoint, ImmediateActi var rpcError rpc.Error if errors.As(err, &rpcError) { ec := rpcError.ErrorCode() - f.Logger.Info("[JSON RPC Response Error]", "Error Code", ec, "Error", rpcError) - // we always attribute JSON RPC error as sender's fault, i.e no connection rotation - return CurrentRPC, Return + f.Logger.Warn("[JSON RPC Response Error]", "Curr Rpc Fault", f.numberRpcFault, "Error Code", ec, "Error", rpcError) + // we always attribute JSON RPC error as receiver's fault, i.e new connection rotation + return NewRPC, Return } // If no http response or no rpc response is returned, it is a connection issue, // since we can't accurately attribute the network issue to neither sender nor receiver // side. Optimistically, switch rpc client - f.Logger.Info("[Default Response Error]", err) + f.Logger.Warn("[Default Response Error]", "Curr Rpc Fault", f.numberRpcFault, "error", err) return NewRPC, Retry } diff --git a/common/geth/multihoming_client_test.go b/common/geth/multihoming_client_test.go index c06e7e5d43..64b29c3dba 100644 --- a/common/geth/multihoming_client_test.go +++ b/common/geth/multihoming_client_test.go @@ -122,7 +122,7 @@ func TestMultihomingClientSenderFaultZeroRetry(t *testing.T) { // given num retry is 0, when failure arises above, current rpc should becomes the next one index, _ = client.GetRPCInstance() - require.Equal(t, index, 0) + require.Equal(t, index, 1) }