Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add caller func name in rpc error log #529

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/geth/failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewFailoverController(logger logging.Logger, rpcUrls []string) (*FailoverCo

// ProcessError attributes the error and updates total number of fault for RPC
// It returns if RPC should immediately give up
func (f *FailoverController) ProcessError(err error, rpcIndex int) bool {
func (f *FailoverController) ProcessError(err error, rpcIndex int, funcName string) bool {
f.mu.Lock()
defer f.mu.Unlock()
if err == nil {
Expand All @@ -47,7 +47,7 @@ func (f *FailoverController) ProcessError(err error, rpcIndex int) bool {
urlDomain = f.UrlDomains[rpcIndex]
}

nextEndpoint, action := f.handleError(err, urlDomain)
nextEndpoint, action := f.handleError(err, urlDomain, funcName)

if nextEndpoint == NewRPC {
f.numberRpcFault += 1
Expand Down
12 changes: 6 additions & 6 deletions common/geth/handle_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const (

// handleHttpError returns a boolean indicating if the current RPC should be rotated
// the second boolean indicating if should giveup immediately
func (f *FailoverController) handleHttpError(httpRespError rpc.HTTPError, urlDomain string) (NextEndpoint, ImmediateAction) {
func (f *FailoverController) handleHttpError(httpRespError rpc.HTTPError, urlDomain string, funcName string) (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]", "urlDomain", urlDomain, "statusCode", sc, "err", httpRespError)
f.Logger.Info("[HTTP Response Error]", "urlDomain", urlDomain, "statusCode", sc, "funcName", funcName, "err", httpRespError)

if sc >= 200 && sc < 300 {
// 2xx error, however it should not be reachable
Expand All @@ -51,28 +51,28 @@ func (f *FailoverController) handleHttpError(httpRespError rpc.HTTPError, urlDom
// 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
func (f *FailoverController) handleError(err error, urlDomain string) (NextEndpoint, ImmediateAction) {
func (f *FailoverController) handleError(err error, urlDomain string, funcName string) (NextEndpoint, ImmediateAction) {

var httpRespError rpc.HTTPError
if errors.As(err, &httpRespError) {
// if error is http error, i.e. non 2xx error, it is handled here
// if it is 2xx error, the error message is nil, https://github.com/ethereum/go-ethereum/blob/master/rpc/http.go,
// execution does not enter here.
return f.handleHttpError(httpRespError, urlDomain)
return f.handleHttpError(httpRespError, urlDomain, funcName)
} else {
// it might be http2xx error, websocket error or ipc error. Parse json error code
var rpcError rpc.Error
if errors.As(err, &rpcError) {
ec := rpcError.ErrorCode()
f.Logger.Warn("[JSON RPC Response Error]", "urlDomain", urlDomain, "errorCode", ec, "err", rpcError)
f.Logger.Warn("[JSON RPC Response Error]", "urlDomain", urlDomain, "errorCode", ec, "funcName", funcName, "err", 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.Warn("[Default Response Error]", "urlDomain", urlDomain, "err", err)
f.Logger.Warn("[Default Response Error]", "urlDomain", urlDomain, "funcName", funcName, "err", err)
return NewRPC, Retry
}
}
Loading
Loading