golang-concurrency

Guides writing and reviewing concurrent Go code using goroutines, channels, and sync primitives.

Updated May 9, 2026
One-click install
npx skills add https://github.com/LuminaVault/LuminaVaultShared --skill golang-concurrency-luminavault
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-concurrency
Source: https://github.com/LuminaVault/LuminaVaultShared/tree/main/.agents/skills/golang-concurrency
Command: npx skills add https://github.com/LuminaVault/LuminaVaultShared --skill golang-concurrency-luminavault

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Concurrent Go code is prone to goroutine leaks, race conditions, channel ownership bugs, and deadlocks that are hard to detect in review and expensive in production. This Skill encodes Go concurrency best practices so AI agents write and review concurrent code correctly the first time. ## Core Features & Use Cases - Write mode: Implement goroutines, channels, worker pools, and fan-out/fan-in pipelines with correct shutdown, context propagation, and error handling via errgroup. - Review mode: Audit PR diffs for goroutine leaks, missing ctx.Done() in select, channel ownership violations, and unprotected shared state. - Audit mode: Run up to 5 parallel sub-agents to scan a codebase for concurrency anti-patterns like time.After in hot loops, unbounded spawning, and sync.Map misuse. - Use Case: When asked to fetch 50 URLs with at most 10 concurrent requests and fail-fast behavior, it produces errgroup.WithContext plus SetLimit(10) instead of a hand-rolled worker pool. ## Quick Start Ask the agent to review your Go service's concurrent code for goroutine leaks and race conditions using the golang-concurrency guidelines.

Frequently Asked Questions about golang-concurrency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent goroutine leaks in Go?▼

Give every goroutine a clear exit path: pass a context.Context and select on ctx.Done(), or use a done channel, and wait with sync.WaitGroup or errgroup. Detect leaks in tests with go.uber.org/goleak via goleak.VerifyTestMain in TestMain.

When should I use errgroup instead of sync.WaitGroup?▼

Use errgroup when goroutines return errors, need cancellation of siblings on first error, or need bounded concurrency via SetLimit. Use sync.WaitGroup only for simple fire-and-wait work with no error propagation; Go 1.25+ offers wg.Go for that case.

Should I use channels or mutexes for shared state in Go?▼

Use channels to transfer ownership of data between goroutines, and sync.Mutex or sync.RWMutex to protect shared struct fields. For simple counters and flags prefer typed atomics like atomic.Int64; use sync.Map only for write-once/read-many or disjoint-key workloads.

Why is time.After inside a select loop a problem in Go?▼

Each time.After call allocates a new timer, causing churn in hot loops. Create one time.NewTimer outside the loop and call Reset after each event; on Go versions before 1.23, drain the channel if Stop reports a pending value.

Who should close a channel in Go, sender or receiver?▼

Only the sender closes a channel; closing from the receiver panics if the sender writes after close. Receivers signal completion through a separate done channel or context cancellation, and the producer selects on that signal alongside its send.

When is sync.Map the wrong choice for a concurrent cache?▼

sync.Map is slower for write-heavy workloads with overlapping keys and does not support iteration or length checks well. For frequent writes on shared keys, use a plain map guarded by sync.RWMutex instead; unsynchronized concurrent map access causes a hard crash.