oven-sh/bun · error
RtlGenRandom failed
Error message
RtlGenRandom failed
What it means
Panic inside os_entropy() on Windows: the advapi32 SystemFunction036 call (RtlGenRandom, the same primitive BoringSSL uses) returned failure while filling an entropy chunk. OS randomness is mandatory, so the process aborts with this message naming the failed API.
Solutions
- Check the Windows system state (RtlGenRandom failing is essentially unheard of)
- Inspect for API-hooking/security software interfering with advapi32
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/bun_core/util.rs:2754 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/f1fc8967446643c2.
Report an issue: GitHub.
Appendix: source
Thrown at src/bun_core/util.rs:2754
// SAFETY: chunk is a valid writable slice ≤ 256 bytes.
let rc = unsafe { libc::getentropy(chunk.as_mut_ptr().cast(), chunk.len()) };
if rc != 0 {
panic!("getentropy failed");
}
}
}
#[cfg(windows)]
{
unsafe extern "system" {
// advapi32!SystemFunction036 a.k.a. RtlGenRandom — what BoringSSL uses on Windows.
#[link_name = "SystemFunction036"]
fn RtlGenRandom(buf: *mut u8, len: u32) -> u8;
}
for chunk in bytes.chunks_mut(u32::MAX as usize) {
// SAFETY: chunk fits in u32; RtlGenRandom writes exactly that many bytes.
let ok = unsafe { RtlGenRandom(chunk.as_mut_ptr(), chunk.len() as u32) };
if ok == 0 {
panic!("RtlGenRandom failed");
}
}
}
}
// ── self_exe_path ─────────────────────────────────────────────────────────
// Memoized into a process-lifetime
// static buffer; thread-safe via `Once`. Returns a `&'static ZStr`.
pub fn self_exe_path() -> crate::CrateResult<&'static ZStr> {
static CELL: Once<crate::CrateResult<ZBox>> = Once::new();
let r = CELL.get_or_init(|| {
let path = std::env::current_exe().map_err(|_| crate::CrateError::Unexpected)?;
// Symlink resolution: Rust's
// `current_exe()` already resolves on Linux (`readlink /proc/self/exe`),
// but on Darwin it returns the raw `_NSGetExecutablePath` result and on
// Windows it returns the raw `GetModuleFileNameW` result — neither
// realpaths, so a symlinked argv0 (Darwin) or an un-normalized
// `C:\a\.\b\bun.exe` load path (Windows) leaks through toView on GitHub (pinned to 8c5296ac45)