Bounty
XE-13227 · Bounty

metrics,node: Handler runs preScrape before MaxRequestsInFlight and unsynchronized gauge updates tear /metrics readiness snapshots

Closed · invalid — xe#352 filed 2026-11-11 04:57 UTC by Khanhtnq

Report

Summary

metrics.Handler() and node observability have two coupled concurrency and resource-amplification bugs on /metrics (mounted on OpsMux in api/observability.go:58-70 at :60, which intentionally bypasses HTTP rate limiting):

  1. preScrape runs outside MaxRequestsInFlight: 4 and evaluates libp2p peer slices twice per scrape:

    • In metrics/metrics.go:159-178, Handler() invokes (*fn)() (o.publishDerived) before promhttp.HandlerFor(..., MaxRequestsInFlight: 4) enforces the 4-request concurrency cap.
    • Every excess concurrent /metrics request that promhttp immediately sheds with 503 Service Unavailable still executes o.publishDerived(), which calls o.peerCount() twice (node/observability.go:331 and o.ready() at node/observability.go:338 -> 468), locking libp2p's swarm mutex and allocating peer slices twice per rejected request.
  2. Torn multi-metric readiness snapshots between o.publish, o.publishDerived, and Registry.Gather():

    • o.sample() -> o.publish(s) (node/observability.go:283-315), o.publishDerived() (node/observability.go:317-356), and Registry.Gather() mutate and read 20+ interrelated gauges (xe_ready, xe_ready_check{check=...}, xe_ready_check_evaluated{check=...}, xe_healthy, xe_peer_count) without mutual exclusion.
    • When o.publish(s) updates gauges concurrently with an active /metrics scrape, Registry.Gather() can emit contradictory readiness states in a single scrape payload (e.g. xe_ready 1 alongside xe_ready_check{check=...} 0).

Locations (origin/master @ 89a542ea)

  • metrics/metrics.go:159-178
  • node/observability.go:122-134, 167-173, 283-356, 442-471
  • api/observability.go:58-70

Thread

XE deskteam2026-11-20 00:24 UTCgithub

Thanks for the report. We read it against the code and could not confirm a bug in what it describes.

This report is closed as invalid. If we have missed something, file a new report that links https://bounty.xe.network/XE-13227 and says what; it is read like any other.