Sobes.tech
Junior — Middle

What are the consequences if the current goroutine's stack exceeds its limit?

sobes.tech AI

Answer from AI

If the current goroutine's stack in Go exceeds its limit, automatic stack expansion occurs. Unlike traditional threads with a fixed stack size, goroutine stacks are dynamic and start small (usually 2 KB), increasing as needed.

Consequences:

  • The contents of the old stack are copied to a new, larger one.
  • This may cause a slight delay during expansion.
  • If the stack cannot be expanded (for example, due to memory exhaustion), the program may panic with the error "runtime: goroutine stack exceeds limit".

Thus, exceeding the stack limit does not lead to an immediate crash but to a dynamic increase, which in extreme conditions may cause a panic.