Skip to content

zetaclient: telemetry /pingrtt crashes process via concurrent map access #4582

Open

Description

@kingpinXD

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 — pingRTT map allocated once in outer scope
  • zetaclient/tss/healthcheck.go:86-93 — pinger goroutines write to it, then SetPingRTT(pingRTT) passes the same reference every tick
  • zetaclient/metrics/telemetry.go:59-63 — SetPingRTT stores the reference directly, no copy
  • zetaclient/metrics/telemetry.go:65-69 — GetPingRTT returns the live reference and releases the mutex on return
  • zetaclient/metrics/telemetry.go:323-337 — pingRTTHandler ranges the map at line 327 with no lock held
  • zetaclient/metrics/telemetry.go:311-321 — connectedPeersHandler has 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's recover() in pkg/bg/bg.go:48 (and that recover wraps the pinger goroutine, not the HTTP handler goroutine).
  • net/http.Server's built-in recover() in conn.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:

  1. In zetaclient/tss/healthcheck.go, allocate a fresh pingRTT map 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
    }
  2. In zetaclient/metrics/telemetry.go, take a snapshot under the lock in pingRTTHandler so 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

  1. added
    zetaclient
    on May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug_bountyzetaclient

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions