Rust: thread 'main' has overflowed its stack — fatal runtime error: stack overflow
Recursion (or huge stack allocations) exhausted the thread's stack.
thread 'main' has overflowed its stackfatal runtime error: stack overflowthread 'main' has overflowed its stack fatal runtime error: stack overflowProcess finished with exit code 134 (interrupted by signal 6: SIGABRT) RustSIGABRT stack overflow Rust Meaning
Add a base case or convert recursion to iteration, avoid large arrays on the stack ([0u8; 10_000_000] → Vec or Box), and for deep legitimate recursion spawn a thread with a bigger stack (thread::Builder::new().stack_size(64*1024*1024)). Debug builds use more stack than release.
Common causes
- Infinite or very deep recursion
- Large stack arrays/structs
- Recursive Drop/Debug on deep linked lists/trees
- Async recursion without boxing (compile error instead)
- Default 8 MB (2 MB for spawned threads) limit
⚡ Quick fix
- Fix the base case or iterate with an explicit stack
- Move big buffers to the heap (
vec![0; n]/Box) - Run in a thread with a larger stack
Detailed fix by platform
Rust
std::thread::Builder::new().stack_size(64 << 20).spawn(run)?.join().unwrap();
How to diagnose
- Recursion — Depth/base case?
- Stack — Large arrays?
- Thread — Stack size?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- fatal error: stack overflow Go: runtime: goroutine stack exceeds 1000000000-byte limit — fatal error: stack overflow
- panic: already borrowed: BorrowMutError Rust: thread 'main' panicked at src/main.rs:8:9: already borrowed: BorrowMutError / already mutably borrowed: BorrowError
- panic: attempt to divide by zero Rust: thread 'main' panicked at src/main.rs:3:13: attempt to divide by zero
Most viewed in Rust
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026