golang-concurrency

Detect goroutine leaks, race conditions, and unsafe channel usage in Go code.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Prevents goroutine leaks and concurrency bugs in Go by enforcing structured concurrency, clear ownership, safe channel practices, and correct synchronization choices.

Core Features & Use Cases

  • Goroutine lifecycle discipline: ensures every goroutine has a clear exit via context cancellation, done signals, or coordinated shutdown.
  • Correct channel ownership and usage: sender-only channel closing, explicit channel directions, and safe send/receive patterns to avoid panics and races.
  • Safe concurrency primitives selection: chooses between channels, mutex/RWMutex, atomic types, sync.Map, sync.Once/singleflight, and errgroup vs WaitGroup based on the task’s error-handling and performance needs.
  • Worker pools, pipelines, and bounded concurrency guidance: supports fan-out/fan-in, pipeline stage shutdown, and recommends errgroup.SetLimit to avoid unbounded goroutine spawning.
  • Review and audit support: provides a checklist to inspect PR diffs and scan codebases for missing ctx.Done() cases, improper closure, unsafe shared memory patterns, and timing pitfalls like time.After in hot loops.

Quick Start

Use this skill to review a Go PR that adds goroutines for background work by checking for goroutine leaks, missing ctx.Done() handling in select statements, and incorrect channel closing or shared-memory patterns.

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

Prevent goroutine leaks by enforcing structured concurrency, ensuring every goroutine has a clear exit via context cancellation, done signals, or coordinated shutdown.

What is the correct way to close channels in Go to avoid panics?

The correct way to close channels is following the sender-owns-close rule, where only the sending goroutine closes the channel to prevent panics and race conditions.

How do I choose between sync.WaitGroup and errgroup for Go fan-out patterns?

Choose errgroup over sync.WaitGroup for fan-out patterns requiring error handling and bounded concurrency, using errgroup.SetLimit to avoid unbounded goroutine spawning.

How do I review a Go PR for race conditions and incorrect sync primitive usage?

Review a Go PR by scanning diffs for missing ctx.Done() cases in select statements, improper channel closure, unsafe shared memory patterns, and incorrect sync/atomic usage.

When should I use singleflight instead of sync.Pool in Go?

Use singleflight to deduplicate concurrent in-flight function calls, whereas sync.Pool is for reusing allocated objects to reduce garbage collection pressure.

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

time.After causes issues in hot loops because it creates a new timer and channel on every iteration, leading to memory leaks and unnecessary garbage collection overhead.