{"record":{"id":"dfc861e5f937cdb7","repo":"dbt-labs/dbt-core","slug":"failed-to-generate-unique-thread-id-bitspace-exha","errorCode":null,"errorMessage":"failed to generate unique thread ID: bitspace exhausted","messagePattern":"failed to generate unique thread ID: bitspace exhausted","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-runtime/src/runtime.rs","lineNumber":141,"sourceCode":"\n        let mut last = NEXT_ID.load(Relaxed);\n        loop {\n            let id = match last.checked_add(1) {\n                Some(id) => id,\n                None => exhausted(),\n            };\n\n            match NEXT_ID.compare_exchange_weak(last, id, Relaxed, Relaxed) {\n                Ok(_) => return ThreadId(NonZeroU64::new(id).unwrap()),\n                Err(id) => last = id,\n            }\n        }\n    }\n}\n\n#[cold]\nfn exhausted() -> ! {\n    panic!(\"failed to generate unique thread ID: bitspace exhausted\")\n}\n","sourceCodeStart":123,"sourceCodeEnd":143,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-runtime/src/runtime.rs#L123-L143","documentation":"dbt-runtime assigns each thread a compact unique ID packed into a finite bit field. When the counter's bit space is fully consumed, `next` calls the #[cold] `exhausted` function which panics — no further unique IDs can be allocated, so allocation of a new thread ID is impossible.","triggerScenarios":"Allocating more unique thread IDs than the internal counter can represent — i.e. an astronomically large number of thread ID generations within the process lifetime (the counter wraps only via panic).","commonSituations":"Practically never seen outside synthetic tests that loop creating and dropping threads billions of times; reported as a hard stop to make ID uniqueness guarantees explicit rather than silently reusing IDs.","solutions":["Report to maintainers — consider widening the ID bit space if your workload legitimately generates this many threads","Restructure the application to reuse threads via a pool instead of repeatedly spawning/destroying threads","Ignore unless hit: this is a theoretical exhaustion guard; reaching it indicates an extreme or buggy thread-creation loop"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Theoretical only; catch-and-report at a coarse boundary\nstd::panic::catch_unwind(|| rt.block_on(main_future)).map_err(|_| \"thread ID space exhausted\")?;","preventionTips":["Reuse pooled threads instead of spawn/drop loops","Treat any occurrence as a bug report, not a normal condition","Avoid synthetic loops that create billions of threads in one process"],"tags":["rust","panic","id-exhaustion","internal-invariant"],"backgroundTag":"value-out-of-range","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}