golang-concurrency

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

1|Updated Jun 2, 2026
One-click install
npx skills add https://github.com/VerifiedOrganic/onboard --skill golang-concurrency-verifiedorganic
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-concurrency
Source: https://github.com/VerifiedOrganic/onboard/tree/main/.agents/skills/golang-concurrency
Command: npx skills add https://github.com/VerifiedOrganic/onboard --skill golang-concurrency-verifiedorganic

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Concurrent Go code is easy to write and hard to get right: goroutine leaks, race conditions, channel ownership violations, and deadlocks slip through reviews and crash production. This Skill encodes Go concurrency best practices so an AI agent writes, reviews, and audits concurrent code with correct lifecycle management, error propagation, and synchronization choices. ## Core Features & Use Cases - Write mode: Implements goroutines, channels, worker pools, and fan-out/fan-in pipelines with proper context cancellation, channel direction, and errgroup-based bounded concurrency. - Review mode: Checks PR diffs for goroutine leaks, missing ctx.Done() in select, unprotected shared state, and channel ownership violations. - Audit mode: Runs up to 5 parallel sub-agents to scan a codebase for fire-and-forget goroutines, mutable globals, unsafe channel usage, and mutex misuse. - Use Case: You need to fetch 50 URLs with at most 10 concurrent requests and cancel everything on the first error — the Skill produces an errgroup.WithContext + SetLimit(10) solution 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, or to implement a bounded worker pool with proper context cancellation.

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?▼

Every goroutine needs a clear exit path: pass a context.Context and include a ctx.Done() case in every select, or use a done channel. Pair spawns with sync.WaitGroup or errgroup so callers can wait, and add go.uber.org/goleak to TestMain to catch leaks in tests.

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

Use errgroup when goroutines return errors, need cancellation of siblings on first failure, or need bounded concurrency via SetLimit. Use sync.WaitGroup only for simple fire-and-wait work with no error propagation; on Go 1.25+, wg.Go simplifies 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, and reserve sync.Map for write-once/read-many workloads.

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

Only the sender (producer) closes a channel; closing from the receiver panics if the sender writes after close. If a consumer needs to stop early, signal the producer through a separate done channel or context cancellation and let the producer close the data channel.

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

Each time.After call allocates a new timer, causing repeated allocation 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.

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

sync.Map is optimized for write-once/read-many patterns or disjoint key sets. For write-heavy workloads with overlapping keys, a plain map guarded by sync.RWMutex is faster, and unsynchronized concurrent map access causes a hard crash rather than a recoverable race.