Description
What happened?
A failed registration can remove exposition-name reservations belonging to collectors that are still registered. A subsequent registration with a conflicting exposition name is then incorrectly accepted.
Reproduced on main at 85d9fb0dca9f064c746470e91b924d253abf8d30.
Reproduction
- Register a counter named
events. - Try to register another counter with the same name and label schema; registration correctly throws.
- Register a gauge named
events_total.
Expected: step 3 is rejected because the original counter still owns the events_total time series name.
Actual: step 3 succeeds. The failed registration released the original counter's events_total and events_created reservations.
The same issue occurs after conflicting help metadata, conflicting metric types with overlapping suffixes, partial exposition-name conflicts, and a failing MultiCollector registration.
Cause
claimExpositionNames() treats a reservation already held by the same Prometheus name as reusable. Both its conflict rollback and validateRegistration()'s failure rollback nevertheless release the whole candidate set, including reservations that predate the failed attempt.
A fix should release only reservations acquired by the current attempt, with claiming and rollback kept inside the existing per-name registered.compute() operation so another successful registration of the same name cannot interleave with rollback.
Five regression tests reproduce the loss while the 27 existing registry tests pass. I have a fix prepared.
AI assistance was used for investigation and regression test preparation.
Activity
fix: preserve existing exposition names after registration failures