• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iotaledger / iota / 28141212998

24 Jun 2026 12:50PM UTC coverage: 67.488% (+0.02%) from 67.464%
28141212998

push

github

web-flow
fix(typed-store): make lazy DBMetrics init race-safe (#11998)

# Description of change

`test_consensus_handler*` and
`test_consensus_commit_prologue_generation` failed intermittently under
parallel (in-process) execution and passed single-threaded. The root
cause is a process-global Prometheus double-registration race in
`DBMetrics`: `DBMetrics::get()` lazily initialized the global metrics
via a non-atomic `OnceCell::get().unwrap_or_else(||
DBMetrics::init(default_registry()))`. When two tests in the same
process build RocksDB-backed `DBMap`s before the cell is set, both run
the fallback, both register the same rocksdb metric names into the
global default registry, and the loser panics with `Result::unwrap()` on
`Err(AlreadyReg)` in `crates/typed-store/src/metrics.rs`.

The fix makes only the lazy `get()` path atomic by switching to
`OnceCell::get_or_init`, so the build-and-register closure runs at most
once across threads. `init(registry)` is left unchanged, so explicit
callers still register into whatever registry they pass. There is no
metrics behavior change otherwise: `get()` still registers into the
default registry on first use and returns the cached instance thereafter
— concurrent first-time initialization simply can no longer
double-register.

This is an in-process (`cargo test` / libtest) hazard. Under nextest
(process-per-test) each test runs in its own process and is isolated, so
CI was unaffected, which is why the flake only reproduced locally.

## Links to any relevant issues

fixes #11705

## How the change has been tested

- [x] Basic tests (linting, compilation, formatting, unit/integration
tests)
- [x] Patch-specific tests (correctness, functionality coverage)
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have checked that new and existing unit tests pass locally with
my changes

Reproduced the panic reliably (failed on the first run) by running the
two `test_consensus_handler*` tests in a... (continued)

1 of 1 new or added line in 1 file covered. (100.0%)

1638 existing lines in 63 files now uncovered.

158590 of 234990 relevant lines covered (67.49%)

475096.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.24
/crates/iota-core/src/execution_cache/writeback_cache.rs


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc