golang-concurrency

Enforce Go concurrency patterns for goroutine lifecycle and channel safety.

2|Updated Feb 12, 2024
One-click install
npx skills add https://github.com/adibfirman/dotfiles --skill golang-concurrency-adibfirman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-concurrency
Source: https://github.com/adibfirman/dotfiles/tree/main/claude/.claude/skills/technical/golang/golang-concurrency
Command: npx skills add https://github.com/adibfirman/dotfiles --skill golang-concurrency-adibfirman

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you design and review Go concurrency so goroutines stop correctly, channels are owned and closed safely, and shared state is synchronized to avoid races and deadlocks.

Core Features & Use Cases

  • Goroutine lifecycle correctness: ensures every goroutine has a clear shutdown path (context cancellation, done signal, or wait mechanism) to prevent leaks.
  • Channel ownership and safety: applies rules like “only the sender closes” and uses channel direction types (chan<-, <-chan) to prevent misuse.
  • Concurrency tool selection: guides when to use errgroup vs sync.WaitGroup, and when to prefer singleflight, pipelines, mutex/RWMutex, atomics, or sync.Pool.

Real-world example: while adding fan-out/fan-in processing to a service, you can use this Skill to refactor the code into a structured pipeline that cancels cleanly on context timeout, avoids pointer-sending pitfalls, and uses bounded concurrency for error propagation.

Quick Start

Ask an AI assistant to write a structured concurrent Go worker pipeline for your task using context cancellation and bounded errgroup.SetLimit, and to review it against goroutine leak and channel ownership rules.

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

To prevent goroutine leaks in Go, ensure every goroutine has a clear shutdown path using context cancellation, done signals, or wait mechanisms. This enforces structured concurrency with explicit shutdown and error propagation to safely manage goroutine lifecycles.

What is the best way to manage channel ownership and closing in Go?

The best way to manage channel ownership in Go is applying the “only the sender closes” rule and using channel direction types like chan<- and <-chan. This prevents channel misuse and ensures safe channel semantics during concurrent processing.

When should I use errgroup vs sync.WaitGroup for Go concurrency?

Use errgroup for Go concurrency when you need bounded concurrency limits and error propagation across goroutines, and sync.WaitGroup when you only need to wait for goroutine completion without error handling. Choose based on your error propagation requirements.

How do I build a structured concurrent Go worker pipeline with context cancellation?

Build a structured Go worker pipeline by using context cancellation, errgroup.SetLimit for bounded concurrency, and channel ownership rules. This approach cancels cleanly on context timeout and uses fan-out/fan-in processing for error propagation.

How does Go singleflight compare to mutexes and atomics for shared state synchronization?

Go singleflight deduplicates concurrent calls to prevent duplicate work, while mutexes and atomics protect shared state from race conditions. Use singleflight for duplicate suppression, and mutexes or atomics for safe concurrent access and race avoidance.

Why does my Go concurrency code have race conditions and deadlocks?

Go concurrency code has race conditions and deadlocks when shared state is not properly synchronized and goroutines lack clear shutdown paths. Apply correct concurrency patterns, channel ownership rules, and structured shutdown mechanisms to avoid these bugs.