fatal error: stack overflow Go Origin: Application & API Last updated 4 Nov 2026

Go: runtime: goroutine stack exceeds 1000000000-byte limit — fatal error: stack overflow

Unbounded recursion consumed the goroutine's stack until it hit the 1 GB limit.

Exact message you may see runtime: goroutine stack exceeds 1000000000-byte limitfatal error: stack overflowgoroutine stack exceeds 1000000000-byte limitruntime: sp= stack=[ ] fatal error: stack overflow
Seen on: Go

Meaning

The stack trace repeats the same function many times. Add a base case, convert deep recursion to iteration, or break accidental infinite recursion such as a String() method that formats itself, or MarshalJSON calling json.Marshal on the same type.

Common causes

  • Missing or unreachable base case
  • String() calling fmt.Sprintf("%v", itself)
  • MarshalJSON/UnmarshalJSON recursing into itself
  • Cyclic data structures traversed naively
  • Mutual recursion

⚡ Quick fix

  1. Fix the base case
  2. In String(): convert to a plain type (type plain T; fmt.Sprintf("%v", plain(t)))
  3. Use a visited set for graphs

Detailed fix by platform

Go

  1. Look at the top lines of the trace for the repeating function

How to diagnose

  1. Trace — Same function repeated?
  2. Method — String/MarshalJSON?
  3. Base — Exit condition?

🔧 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):

invalid memory address or nil pointer dereference — Go: panic: runtime error: invalid memory address or nil pointer dereference (Go)invalid memory addres…panic: assignment to entry in nil map — Go: panic: assignment to entry in nil map (Go)panic: assignment to …panic: interface conversion — Go: panic: interface conversion: interface {} is string, not int (Go)panic: interface conv…panic: runtime error: index out of range — Go: panic: runtime error: index out of range [3] with length 3 (Go)panic: runtime error:…panic: runtime error: integer divide by zero — Go: panic: runtime error: integer divide by zero (Go)panic: runtime error:…panic: slice bounds out of range — Go: panic: runtime error: slice bounds out of range [:5] with capacity 3 (Go)panic: slice bounds o…reflect: call of reflect.Value.X on zero Value — Go: panic: reflect: call of reflect.Value.Elem on zero Value (Go)reflect: call of refl…fatal err…

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.