golang-pitfalls-concurrency-practice

Installation
SKILL.md

Golang Pitfalls: Concurrency Practice

Source material: mistakes #61-74 from 100 Go Mistakes and How to Avoid Them (teivah/100-go-mistakes).

Apply these rules when writing practical Go concurrency code.

61. Propagating an inappropriate context (#61)

  • An HTTP request context is canceled when: the client's connection closes, the request is canceled (HTTP/2), or the response is written.
  • If you spawn an async goroutine (e.g., Kafka publish) using the request context, the context may be canceled right after the response is written, silently dropping the work.
  • Propagate with care; from Go 1.21 you can use context.WithoutCancel(parent) for work that must outlive the request.

62. Starting a goroutine without knowing when to stop it (#62)

  • Every goroutine is a resource; always have a plan to stop it — otherwise goroutine/resource leaks.
  • Signaling alone (a canceled context) isn't enough; the parent may exit before the goroutine cleans up.
  • If a goroutine's lifetime is bound to the app's, wait for it to finish before returning: expose a close() (use defer w.close()) or wait for completion.

63. Goroutines and loop variables (#63)

Installs
2
First Seen
9 days ago
golang-pitfalls-concurrency-practice — fabianoflorentino/golang-agent-skills