Repository navigation
Description
Summary
HealthcheckWorker allocates a single pingRTT map and reuses the same reference every tick. The /pingrtt HTTP handler iterates that live map after releasing the mutex, while pinger goroutines write to it on the next tick. Go's runtime detects the concurrent map access and calls runtime.throw(), which terminates the zetaclient process. recover() does not catch this — runtime throws bypass the defer/recover machinery entirely.
Where
zetaclient/tss/healthcheck.go:45-49—pingRTTmap allocated once in outer scopezetaclient/tss/healthcheck.go:86-93— pinger goroutines write to it, thenSetPingRTT(pingRTT)passes the same reference every tickzetaclient/metrics/telemetry.go:59-63—SetPingRTTstores the reference directly, no copyzetaclient/metrics/telemetry.go:65-69—GetPingRTTreturns the live reference and releases the mutex on returnzetaclient/metrics/telemetry.go:323-337—pingRTTHandlerranges the map at line 327 with no lock heldzetaclient/metrics/telemetry.go:311-321—connectedPeersHandlerhas the same shape with a slice (no runtime throw, but produces a data race / corrupted JSON)
Why recovery doesn't help
concurrent map iteration and map write is a runtime throw, not a panic. It bypasses:
bg.Work'srecover()inpkg/bg/bg.go:48(and that recover wraps the pinger goroutine, not the HTTP handler goroutine).net/http.Server's built-inrecover()inconn.serve().
Process exits and only restarts via the external supervisor.
Trigger
Any HTTP GET /pingrtt that overlaps with an active pinger tick. Default Interval = 30s with a 5s ping timeout, so writes are spread over a ~5s window per tick. Steady polling collapses this to seconds. Even a benign Prometheus/Datadog scraper polling /pingrtt will hit this on a long-running node — no attacker required.
In the bundled contrib/localnet/docker-compose.yml, port 8123 is not published (only 6061 pprof and 8886 metrics are), so the localnet exposure is container-internal only. Production exposure depends on operator firewall posture.
Fix
Two-part:
-
In
zetaclient/tss/healthcheck.go, allocate a freshpingRTTmap inside each ticker cycle so the map handed to telemetry is never written to again after the call:pinger := func(ctx context.Context, _ *ticker.Ticker) error { localPingRTT := make(map[peer.ID]int64) var wg sync.WaitGroup // ... wg.Wait() p.Telemetry.SetPingRTT(localPingRTT) return nil }
-
In
zetaclient/metrics/telemetry.go, take a snapshot under the lock inpingRTTHandlerso the handler is decoupled from any future writes regardless of caller behavior:t.mu.Lock() snapshot := make(map[peer.ID]int64, len(t.rtt)) for k, v := range t.rtt { snapshot[k] = v } t.mu.Unlock()
Apply the same snapshot pattern to
connectedPeersHandler.
A previous fix on this code path (commits b5c3e03 / fe6d8e7) was lost when healthcheck moved into zetaclient/tss/healthcheck.go.
Impact
- Single-node liveness: targeted zetaclient process exits and is restarted by the supervisor. Other validators unaffected.
- Self-triggers from monitoring scrapers, so this manifests during normal operation, not just under attack.
Reference
HackenProof report: https://dashboard.hackenproof.com/manager/companies/zetachain/zetachain-blockchain-software/reports/ZCNode-248
Activity