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

**Code:** `fatal error: stack overflow` · **Category:** Go · **Seen on:** Go

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/go/goroutine-stack-exceeds-limit)
