From 164eeb84c0af028691b7691bd0f8c73ab662ef68 Mon Sep 17 00:00:00 2001 From: Weixie Cui Date: Thu, 9 Jul 2026 12:15:00 +0800 Subject: [PATCH] internal/testlog: clone attrs before appending WithAttrs and terminalFormat appended to h.attrs directly, which can mutate the shared slice when it has spare capacity. Clone attrs first to avoid corrupting parent handler state. --- internal/testlog/testlog.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/testlog/testlog.go b/internal/testlog/testlog.go index 8a3ea85438..8993d073c7 100644 --- a/internal/testlog/testlog.go +++ b/internal/testlog/testlog.go @@ -22,6 +22,7 @@ import ( "context" "fmt" "log/slog" + "slices" "sync" "github.com/ethereum/go-ethereum/log" @@ -76,7 +77,7 @@ func (h *bufHandler) WithAttrs(attrs []slog.Attr) slog.Handler { copy(records[:], h.buf[:]) return &bufHandler{ buf: records, - attrs: append(h.attrs, attrs...), + attrs: append(slices.Clone(h.attrs), attrs...), level: h.level, } } @@ -186,7 +187,7 @@ func (h *bufHandler) terminalFormat(r slog.Record) string { return true }) - attrs = append(h.attrs, attrs...) + attrs = append(slices.Clone(h.attrs), attrs...) fmt.Fprintf(buf, "%s[%s] %s ", lvl, r.Time.Format(termTimeFormat), r.Message) if length := len(r.Message); length < 40 {