Skip to content

fix: replace *http.Request in log field with JSON-safe fields#896

Closed
seeforschauer wants to merge 1 commit into
flashbots:developfrom
seeforschauer:fix/894-json-log-request-marshal
Closed

fix: replace *http.Request in log field with JSON-safe fields#896
seeforschauer wants to merge 1 commit into
flashbots:developfrom
seeforschauer:fix/894-json-log-request-marshal

Conversation

@seeforschauer
Copy link
Copy Markdown

Change Description

Replace raw *http.Request struct in logrus field with individual JSON-serializable fields (method, url, contentType).

*http.Request contains GetBody func() (io.ReadCloser, error) which encoding/json cannot marshal. When mev-boost runs with -json flag, logrus JSONFormatter fails to serialize the field and silently drops the log entry.

Root Cause

server/register_validator.go:51 passed the full request struct:

log.WithFields(logrus.Fields{
    "request": req,  // contains func() — breaks json.Marshal
}).Debug(...)

Fix

Extract the useful fields instead:

log.WithFields(logrus.Fields{
    "method":      req.Method,
    "url":         req.URL.String(),
    "contentType": req.Header.Get("Content-Type"),
}).Debug(...)

Fixes #894.

Testing

  • go build ./... — passes
  • go test ./server/... — all pass

Fixes flashbots#894.

*http.Request contains GetBody func() which encoding/json cannot
marshal. When using JSON log format (-json flag), logrus silently
drops the log entry.

Replace the raw request with method, url, and content-type fields.
@seeforschauer
Copy link
Copy Markdown
Author

Closing — duplicate of #895 by @dom-nie which addresses the same issue. Apologies for not checking existing PRs first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: JSON log format breaks on registerValidator due to *http.Request field containing func() type

1 participant