Skip to content

fix(log): sync TerminalHandler with upstream #35055 #35074 #35141 - #2837

Merged
gzliudan merged 4 commits into
XinFinOrg:dev-upgradefrom
gzliudan:fix-log-terminal-handler-attrs-alias
Oct 27, 2026
Merged

gzliudan merged 4 commits into
XinFinOrg:dev-upgradefrom
gzliudan:fix-log-terminal-handler-attrs-alias

Conversation

@gzliudan

@gzliudan gzliudan commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Ports the three upstream fixes that log/handler.go never carried. With this, the file is identical to go-ethereum's log/handler.go at 409aaefac (checked with diff against geth origin/master, zero lines).

  1. log: return TerminalHandler write errors from Handle ethereum/go-ethereum#35055 (ab20d50db) -- Handle discarded the error of the underlying writer, so a failing TerminalHandler silently dropped records. Propagate it to the caller instead, matching go-ethereum. In-tree this reaches only callers holding the handler directly: GlogHandler.Handle returns it onwards, while log.Logger.Write has no error return and drops it (upstream included), so records logged through the Logger facade behave exactly as before.
  2. log: share mutex in log handles with same writer and other fields ethereum/go-ethereum#35074 (eea624274) -- mu was a sync.Mutex value, so every handler derived by WithAttrs created its own mutex over the same writer. Make it a *sync.Mutex and hand the parent's mutex down, so a handler family serializes its writes.
  3. log: clone terminal handler attrs ethereum/go-ethereum#35141 (409aaefac) -- WithAttrs appended to h.attrs directly, so when the parent's attribute slice had spare capacity two sibling handlers wrote into the same backing array and overwrote each other's attributes. Clone it first.

This is a follow-up to #2825: the same attribute-aliasing class fixed there inside internal/testlog also existed in the production TerminalHandler. It is kept in a separate PR because #2825 is test-only and already reviewed.

Evidence

Mutation checks, one fix reverted at a time with the tests unchanged:

  • error dropped (h.wr.Write(buf); return nil) -- TestTerminalHandlerReportsWriteErrors fails with Handle error is <nil>, want write refused.
  • WithAttrs handing down &sync.Mutex{} -- TestTerminalHandlerSharesMutex fails with sub-handler does not share the parent's mutex, and TestTerminalHandlerDerivedHandlerBlocksOnParentMutex fails with sub-handler wrote without waiting for the parent's mutex.
  • append(h.attrs, attrs...) without the clone -- TestTerminalHandlerKeepsSiblingAttributes fails with first child's attribute was overwritten: child="second".

The mutex check is deterministic: the test holds the parent's mutex, so a derived handler with its own mutex writes through at once instead of blocking.

Validation

  • make all exits 0.
  • gofmt / goimports clean; go vet ./log/... passes.
  • go test -count=1 ./log/... passes (four new tests plus the existing ones); go test -race ./log/ passes.
  • golangci-lint 2.15.0 --new-from-rev=f85916e0c3 ./log/... (current dev-upgrade tip) -- 0 issues.
  • Diff against go-ethereum origin/master (8817f99f9): log/handler.go identical.

Merge Danger

Door: two-way -- one production file with three independent hunks (error return, mutex pointer, clone) plus one additive test file. Reverting any hunk restores the previous behaviour byte for byte.

Blast Radius: TerminalHandler is only built through NewTerminalHandler / NewTerminalHandlerWithLevel (cmd/bootnode, cmd/abigen, cmd/puppeth, internal/debug/flags.go, p2p/simulations/adapters, p2p/simulations/examples (the ping-pong example program), plus tests); there are no struct literals outside the package, so every instance has an initialized mu. Behavioural deltas: sub-handlers now share the parent's mutex, and Handle returns the writer error instead of nil. No API or signature change.

No file overlap with #2825 (internal/testlog/*), so the two can be merged in any order.

Ref: go-ethereum ethereum#35055 (ab20d50db), ethereum#35074 (eea624274), ethereum#35141 (409aaefac)

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b740fc4a-f5d4-440f-9bf3-047ec81630e8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gzliudan
gzliudan force-pushed the fix-log-terminal-handler-attrs-alias branch 2 times, most recently from 6552217 to 50fb6ac Compare October 26, 2026 05:32
@gzliudan
gzliudan force-pushed the fix-log-terminal-handler-attrs-alias branch 2 times, most recently from 217a551 to 2a69f8c Compare October 27, 2026 10:02


Handle discarded the error of the underlying writer, so a failing
TerminalHandler silently dropped records. Propagate it to the caller
instead, matching go-ethereum.

Ref: ethereum#35055
…#35074

mu was a struct value, so every handler derived by WithAttrs created its
own mutex over the same writer. Make it a pointer and hand the parent's
mutex down, so writes through a handler family stay serialized.

Ref: ethereum#35074
WithAttrs appended to h.attrs directly, so when the parent's attribute
slice had spare capacity two sibling handlers wrote into the same backing
array and overwrote each other's attributes. Clone it first.

Ref: ethereum#35141
One case per upstream fix ported on this branch, two for the shared mutex:
- a rejected write has to reach the caller (ethereum#35055);
- a handler derived by WithAttrs has to share the parent's mutex, and to
  wait for it while the parent holds it (ethereum#35074);
- two sibling handlers must not overwrite each other's attributes when the
  parent's attribute slice has spare capacity (ethereum#35141).

Ref: ethereum#35055, ethereum#35074, ethereum#35141
@gzliudan
gzliudan force-pushed the fix-log-terminal-handler-attrs-alias branch from 2a69f8c to c2a9ecf Compare October 27, 2026 10:23
@gzliudan
gzliudan merged commit 1567284 into XinFinOrg:dev-upgrade Oct 27, 2026
16 checks passed
@gzliudan
gzliudan deleted the fix-log-terminal-handler-attrs-alias branch October 27, 2026 10:57
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.

4 participants