thread 'main' has overflowed its stack (SIGABRT) Rust Origin: Application & API Last updated 5 Nov 2026

Rust: thread 'main' has overflowed its stack — fatal runtime error: stack overflow

Recursion (or huge stack allocations) exhausted the thread's stack.

Exact message you may see 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
Seen on: Rust Linux

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

  1. Fix the base case or iterate with an explicit stack
  2. Move big buffers to the heap (vec![0; n]/Box)
  3. Run in a thread with a larger stack

Detailed fix by platform

Rust

  1. std::thread::Builder::new().stack_size(64 << 20).spawn(run)?.join().unwrap();

How to diagnose

  1. Recursion — Depth/base case?
  2. Stack — Large arrays?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

fatal error: stack overflow — Go: runtime: goroutine stack exceeds 1000000000-byte limit — fatal error: stack overflow (Go)fatal error: stack ov…panic: already borrowed: BorrowMutError — Rust: thread 'main' panicked at src/main.rs:8:9: already borrowed: BorrowMutError / already mutably borrowed: BorrowError (Rust)panic: already borrow…panic: attempt to divide by zero — Rust: thread 'main' panicked at src/main.rs:3:13: attempt to divide by zero (Rust)panic: attempt to div…panic: attempt to subtract with overflow — Rust: thread 'main' panicked at src/main.rs:4:13: attempt to subtract with overflow (Rust)panic: attempt to sub…panic: called Option::unwrap() on a None value — Rust: thread 'main' panicked at src/main.rs:4:20: called `Option::unwrap()` on a `None` value (Rust)panic: called Option:…panic: called Result::unwrap() on an Err value — Rust: thread 'main' panicked at src/main.rs:5:36: called `Result::unwrap()` on an `Err` value: ParseIntError { kind: InvalidDigit } (Rust)panic: called Result:…panic: index out of bounds: the len is N but the index is M — Rust: thread 'main' panicked at src/main.rs:5:5: index out of bounds: the len is 3 but the index is 3 (Rust)panic: index out of b…PoisonError: poisoned lock: another task failed inside — Rust: thread 'main' panicked: called `Result::unwrap()` on an `Err` value: PoisonError { .. } — poisoned lock: another task failed inside (Rust)PoisonError: poisoned…thread 'm…

Explore the map of this error Full error map →

🧠 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.