Skip to content

Commit

Permalink
rpc: Remove response data from response failure logs (backport cometb…
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored and DongLieu committed May 13, 2024
1 parent 68b6c94 commit 48f0d61
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- `[rpc]` Remove response data from response failure logs in order
to prevent large quantities of log data from being produced
([\#654](https://github.com/cometbft/cometbft/issues/654))
6 changes: 3 additions & 3 deletions rpc/jsonrpc/server/http_json_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han
fmt.Errorf("error reading request body: %w", err),
)
if wErr := WriteRPCResponseHTTPError(w, http.StatusBadRequest, res); wErr != nil {
logger.Error("failed to write response", "res", res, "err", wErr)
logger.Error("failed to write response", "err", wErr)
}
return
}
Expand All @@ -48,7 +48,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han
if err := json.Unmarshal(b, &request); err != nil {
res := types.RPCParseError(fmt.Errorf("error unmarshaling request: %w", err))
if wErr := WriteRPCResponseHTTPError(w, http.StatusInternalServerError, res); wErr != nil {
logger.Error("failed to write response", "res", res, "err", wErr)
logger.Error("failed to write response", "err", wErr)
}
return
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han
wErr = WriteRPCResponseHTTP(w, responses...)
}
if wErr != nil {
logger.Error("failed to write responses", "res", responses, "err", wErr)
logger.Error("failed to write responses", "err", wErr)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions rpc/jsonrpc/server/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func RecoverAndLogHandler(handler http.Handler, logger log.Logger) http.Handler
// If RPCResponse
if res, ok := e.(types.RPCResponse); ok {
if wErr := WriteRPCResponseHTTP(rww, res); wErr != nil {
logger.Error("failed to write response", "res", res, "err", wErr)
logger.Error("failed to write response", "err", wErr)
}
} else {
// Panics can contain anything, attempt to normalize it as an error.
Expand All @@ -207,7 +207,7 @@ func RecoverAndLogHandler(handler http.Handler, logger log.Logger) http.Handler

res := types.RPCInternalError(types.JSONRPCIntID(-1), err)
if wErr := WriteRPCResponseHTTPError(rww, http.StatusInternalServerError, res); wErr != nil {
logger.Error("failed to write response", "res", res, "err", wErr)
logger.Error("failed to write response", "err", wErr)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions rpc/jsonrpc/server/http_uri_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func makeHTTPHandler(rpcFunc *RPCFunc, logger log.Logger) func(http.ResponseWrit
return func(w http.ResponseWriter, r *http.Request) {
res := types.RPCMethodNotFoundError(dummyID)
if wErr := WriteRPCResponseHTTPError(w, http.StatusNotFound, res); wErr != nil {
logger.Error("failed to write response", "res", res, "err", wErr)
logger.Error("failed to write response", "err", wErr)
}
}
}
Expand All @@ -45,7 +45,7 @@ func makeHTTPHandler(rpcFunc *RPCFunc, logger log.Logger) func(http.ResponseWrit
fmt.Errorf("error converting http params to arguments: %w", err),
)
if wErr := WriteRPCResponseHTTPError(w, http.StatusInternalServerError, res); wErr != nil {
logger.Error("failed to write response", "res", res, "err", wErr)
logger.Error("failed to write response", "err", wErr)
}
return
}
Expand All @@ -58,7 +58,7 @@ func makeHTTPHandler(rpcFunc *RPCFunc, logger log.Logger) func(http.ResponseWrit
if err != nil {
if err := WriteRPCResponseHTTPError(w, http.StatusInternalServerError,
types.RPCInternalError(dummyID, err)); err != nil {
logger.Error("failed to write response", "res", result, "err", err)
logger.Error("failed to write response", "err", err)
return
}
return
Expand All @@ -71,7 +71,7 @@ func makeHTTPHandler(rpcFunc *RPCFunc, logger log.Logger) func(http.ResponseWrit
err = WriteRPCResponseHTTP(w, resp)
}
if err != nil {
logger.Error("failed to write response", "res", result, "err", err)
logger.Error("failed to write response", "err", err)
return
}
}
Expand Down

0 comments on commit 48f0d61

Please sign in to comment.