XE-13227 · Bounty
metrics,node: Handler runs preScrape before MaxRequestsInFlight and unsynchronized gauge updates tear /metrics readiness snapshots
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):
-
preScraperuns outsideMaxRequestsInFlight: 4and evaluates libp2p peer slices twice per scrape:- In
metrics/metrics.go:159-178,Handler()invokes(*fn)()(o.publishDerived) beforepromhttp.HandlerFor(..., MaxRequestsInFlight: 4)enforces the 4-request concurrency cap. - Every excess concurrent
/metricsrequest thatpromhttpimmediately sheds with503 Service Unavailablestill executeso.publishDerived(), which callso.peerCount()twice (node/observability.go:331ando.ready()atnode/observability.go:338 -> 468), locking libp2p's swarm mutex and allocating peer slices twice per rejected request.
- In
-
Torn multi-metric readiness snapshots between
o.publish,o.publishDerived, andRegistry.Gather():o.sample()->o.publish(s)(node/observability.go:283-315),o.publishDerived()(node/observability.go:317-356), andRegistry.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/metricsscrape,Registry.Gather()can emit contradictory readiness states in a single scrape payload (e.g.xe_ready 1alongsidexe_ready_check{check=...} 0).
Locations (origin/master @ 89a542ea)
metrics/metrics.go:159-178node/observability.go:122-134, 167-173, 283-356, 442-471api/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.