{"id":"XE-13227","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"352","source_url":"https://github.com/xeprotocol/xe/issues/352","reporter_id":2,"title":"metrics,node: Handler runs preScrape before MaxRequestsInFlight and unsynchronized gauge updates tear /metrics readiness snapshots","area":"node-api","claimed_tier":null,"assessed_tier":null,"verdict":"invalid","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"invalid","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:00.854391+00:00","updated_at":"2026-11-20T00:25:43.072645+00:00","source_created_at":"2026-11-11T04:57:08+00:00","told_at":"2026-11-20T00:24:39+00:00","status_changed_at":"2026-11-20T00:08:43.574956+00:00","url":"https://bounty.xe.network/XE-13227","body":"### Summary\n\n`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):\n\n1. **`preScrape` runs outside `MaxRequestsInFlight: 4` and evaluates libp2p peer slices twice per scrape**:\n   - In `metrics/metrics.go:159-178`, `Handler()` invokes `(*fn)()` (`o.publishDerived`) *before* `promhttp.HandlerFor(..., MaxRequestsInFlight: 4)` enforces the 4-request concurrency cap.\n   - 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.\n\n2. **Torn multi-metric readiness snapshots between `o.publish`, `o.publishDerived`, and `Registry.Gather()`**:\n   - `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.\n   - 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`).\n\n### Locations (`origin/master` @ `89a542ea`)\n\n- `metrics/metrics.go:159-178`\n- `node/observability.go:122-134, 167-173, 283-356, 442-471`\n- `api/observability.go:58-70`","patch_refs":[{"id":542,"repo":"xeprotocol/xe","kind":"pr","ref":"353","title":"fix(metrics,node): gate preScrape concurrency and serialize readiness scrape snapshots","url":"https://github.com/xeprotocol/xe/pull/353","note":"","state":"open","author":"Khanhtnq","added_by":"desk","created_at":"2026-11-14T20:42:19.697417+00:00"}],"thread":[{"id":13026,"source":"github","source_ref":"7026258931","author":"XE desk","team":true,"body":"Thanks for the report. We read it against the code and could not confirm a bug in what it describes.\n\nThis report is closed as invalid. If we have missed something, file a new report that links\nhttps://bounty.xe.network/XE-13227 and says what; it is read like any other.","created_at":"2026-11-20T00:24:39+00:00"}]}