Skip to catalogue

264

goroutine

also Go channel, goroutine leak

A goroutine is cheap to start and easy to leak. Cancel it, or it runs until the process dies.

What is goroutine?

A goroutine is a lightweight thread scheduled by the Go runtime. A leak is one blocked forever on a channel send, a channel receive, or a call with no timeout. The context is how you cancel a tree of work. GOMAXPROCS is the number of OS threads, not the number of goroutines you may start.

Why does goroutine matter when vibe coding?

The handler does go doWork() and returns. The work outlives the request, uses a closed context, and piles up. Nothing is waiting for the error.

How do you do goroutine?

Start a goroutine with a context that dies when the request or the owner dies. Bound how many run. Make the channel send select on cancellation. Wait for shutdown.

How do you ask a model for goroutine?

Run (work) in a goroutine tied to (context). Stop when the context is cancelled. Bound the number in flight. Do not start one per request and ignore it. Surface the error.

What goes wrong with goroutine?

A channel with no buffer and no receiver yet. The send blocks forever and the goroutine never reaches your cancel check.

adjacent