Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Leaked resources: files, connections, goroutines card 5 of 6

Go: goroutines blocked forever

builds on: Error handling idioms across languages
BAD: the agent's helper returns the first URL that answers, and it returns the right one in tests. **Tell:** an unbuffered channel with many senders but only one receive. Every goroutine except the first to succeed blocks forever on `ch <- u`, so its deferred `Body.Close()` never runs and it keeps a connection. If every request fails, nothing is sent and the caller blocks forever. **Later cost:** goroutines and connections pile up on every call. **BETTER:** use `make(chan string, len(urls))` so every send completes. Have each goroutine send on failure too, for example `""`, and let the caller receive up to `len(urls)` times. Build the requests with a context whose `cancel` the caller defers, which stops the losing requests.
// Go
func firstOK(urls []string) string {
  ch := make(chan string)
  for _, u := range urls {
    go func(u string) {
      r, err := http.Get(u)
      if err != nil { return }
      defer r.Body.Close()
      ch <- u
    }(u)
  }
  return <-ch
}
Terms on this card
goroutine
A lightweight concurrent function in Go, started with `go f()`. It lives until its function returns; a goroutine blocked forever is never freed.
unbuffered channel
A Go channel made with `make(chan T)`. A send blocks until another goroutine receives the value, and the receive blocks until something is sent.
cancel
The function returned by Go's `context.WithCancel` or `WithTimeout`. Calling it stops work tied to the context and frees its timer and bookkeeping.
tell
An observable sign in a diff, transcript or summary that suggests a shortcut or an error.
later cost
The concrete damage a shortcut does after merge, such as a hidden bug, an outage or extra maintenance.
Learn this step by step on Bytewise
Lesson goal: Spot files, connections and locks opened without `with`, try-with-resources or `defer`, as well as `defer` inside loops, goroutines blocked forever and contexts never cancelled. Explain why these pass tests but exhaust resources in production. · the whole lesson