golang-concurrency

Analyzes and generates Go goroutine, channel, synchronization code with cancellation-aware select loops.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents common, hard-to-debug failures in Go concurrent programs—goroutine leaks, race conditions, incorrect channel ownership/closure, and broken cancellation behavior.

Core Features & Use Cases

  • Structured Concurrency Guardrails: Ensures every goroutine has a clear exit strategy using context cancellation, wait groups, or explicit shutdown signals.
  • Channel Correctness: Enforces sender-only channel closing, correct channel direction (chan<- / <-chan), and safe value passing (send copies, not pointers).
  • Practical Concurrency Decisions: Guides when to use channels vs mutexes vs atomics, when to prefer errgroup over WaitGroup, and how to bound concurrency safely.
  • Performance & Reliability Antipattern Avoidance: Flags issues like time.After in hot loops, missing ctx.Done() in select, unbounded goroutine spawning, and mutexes held across I/O.
  • Use Case Examples: Auditing or implementing worker pools, fan-out/fan-in pipelines, concurrent caches, deduplicated in-flight work (singleflight), and cancellation-safe stages.

Quick Start

Use the golang-concurrency skill to review a Go change request for goroutine leaks and channel ownership bugs in the proposed concurrent code.

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 concurrent programs?

To prevent goroutine leaks, ensure every goroutine has a clear exit strategy using context cancellation, wait groups, or explicit shutdown signals. This guarantees structured concurrency and safe goroutine lifecycles without orphaned processes.

When should I use channels vs mutexes for shared data in Golang?

Use channels for passing ownership of data between goroutines, and use mutexes or atomics for protecting shared memory. This Skill guides practical concurrency decisions to ensure safe data passing and avoid unsynchronized memory access.

How do I implement safe worker pools and fan-out/fan-in pipelines in Go?

Implement safe worker pools and pipelines by enforcing sender-owned channel closure, correct channel direction, and bounded concurrency. This prevents common pipeline failures and ensures safe value passing across concurrent stages.

Why does using time.After in hot loops cause concurrency issues in Go?

Using time.After in hot loops causes concurrency issues because it allocates a new timer and channel every iteration without being garbage collected until it fires. This creates memory leaks and degrades performance in long-running goroutines.

How do I handle context cancellation in Go select loops?

Handle context cancellation by always including a ctx.Done() case in your select loops. This ensures goroutines terminate promptly when the context is canceled, preventing blocked sends or receives and avoiding goroutine leaks.

Does errgroup work better than WaitGroup for bounded concurrency in Go?

errgroup is preferred over WaitGroup when you need bounded concurrency and automatic error propagation. It simplifies managing concurrent goroutines by setting a concurrency limit and canceling the context on the first error.