golang-concurrency

Review concurrent Go code for goroutine leaks and channel ownership bugs.

1|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/dashkan/pivox --skill golang-concurrency-dashkan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-concurrency
Source: https://github.com/dashkan/pivox/tree/main/.agents/skills/golang-concurrency
Command: npx skills add https://github.com/dashkan/pivox --skill golang-concurrency-dashkan

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you write and review concurrent Go code without goroutine leaks, race conditions, and channel-ownership bugs that commonly appear in real-world systems.

Core Features & Use Cases

  • Structured concurrency guardrails: Ensures every goroutine has a clear stop path via context.Context, done channels, or explicit shutdown, and that cancellation is respected.
  • Channel correctness rules: Applies sender/receiver channel ownership, enforces channel direction (chan<-, <-chan), and prevents unsafe patterns like receiver-closing data channels.
  • Safe synchronization decisions: Guides correct selection among sync.Mutex, sync.RWMutex, sync/atomic, sync.Map, errgroup, singleflight, and worker pools with SetLimit.
  • Pipeline patterns that don’t leak: Covers fan-out/fan-in and multi-stage pipelines with proper context checks and output channel closing.
  • Use case examples: Build bounded concurrent fetchers, pipeline I/O transformations safely, deduplicate thundering herds with singleflight, and add leak detection using goleak in tests.

Quick Start

Use the golang-concurrency skill to review your Go PR for goroutine leaks, missing ctx.Done() cases in select, unsafe channel closing, and unprotected shared state.

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 when implementing concurrent Go services?

Prevent goroutine leaks by ensuring every goroutine has a clear stop path via context cancellation, done channels, or explicit shutdown logic. Structured concurrency requires checking ctx.Done() in select statements to guarantee deterministic shutdown and avoid orphaned routines.

When do I need to use singleflight in Go concurrency patterns?

Use singleflight in Go when you need to deduplicate thundering herd requests, preventing multiple concurrent identical calls from overwhelming a downstream resource. It suppresses duplicate in-flight calls and shares the result among all waiting callers.

What is the correct way to handle channel ownership and closing in Go pipelines?

Correct channel ownership in Go pipelines dictates that senders own channels and enforce direction using chan<- and <-chan. Receivers must never close data channels; instead, the sender is responsible for closing output channels safely once all sends complete.

How do I choose between sync.Mutex, sync/atomic, and errgroup for Go synchronization?

Choose sync.Mutex or sync.RWMutex for protecting shared state, sync/atomic for simple counter or flag updates, and errgroup for managing concurrent goroutines that need bounded limits via SetLimit and synchronized error propagation.

Can I use goleak to detect goroutine leaks in Go tests?

Yes, you can use goleak in Go tests to detect goroutine leaks by verifying that all goroutines spawned during test execution exit cleanly. Adding goleak checks ensures your pipelines and fan-out/fan-in patterns maintain deterministic shutdown.

What's the best way to build bounded concurrent fetchers in Go?

Build bounded concurrent fetchers in Go using errgroup with SetLimit to cap active worker goroutines. Ensure each fetcher respects context cancellation to achieve structured concurrency and prevent pipeline bottlenecks or resource exhaustion.