golang-concurrency

Enforce structured concurrency patterns in Go code to prevent goroutine leaks and race conditions.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It helps prevent common failures in concurrent Go programs—goroutine leaks, race conditions, incorrect channel ownership, and broken cancellation/error handling—by enforcing safe structured-concurrency patterns.

Core Features & Use Cases

  • Structured concurrency guardrails: ensures every goroutine has a clear shutdown path (typically via context cancellation or channel closure semantics).
  • Safe channel ownership and usage: enforces “sender closes, receiver reads,” uses channel direction types, and avoids sending shared mutable pointers.
  • Correct primitives selection: guides decisions between channels, mutexes, RWMutex, atomics, sync.Map, singleflight, and errgroup/WaitGroup.
  • Common anti-pattern detection: flags time.After-in-select-loop churn, missing ctx.Done() in selects, unbounded goroutine spawning, and mutex/channel misuse.
  • Use case: when building a message-processing pipeline (fan-out/fan-in) for an online service, apply these rules to guarantee workers stop on cancellation, propagate first errors correctly, and avoid hidden shared memory.

Quick Start

Use the golang-concurrency skill to review and fix a Go service change that adds goroutines and channels to a request handler, ensuring it exits cleanly on context cancellation and has correct channel closing and error propagation.

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?

Prevent goroutine leaks by enforcing structured concurrency patterns that ensure every goroutine has a clear shutdown path, typically through context cancellation or channel closure semantics.

What is the correct way to manage channel ownership and closing in Golang?

Correct channel ownership in Golang follows the "sender closes, receiver reads" pattern, utilizes channel direction types, and avoids sending shared mutable pointers to ensure safe data transfer semantics.

How do I choose between mutexes, channels, and sync primitives in Go?

Choosing between channels, mutexes, RWMutex, atomics, sync.Map, singleflight, and errgroup requires evaluating data access patterns, concurrency scope, and error propagation needs to apply correct synchronization primitives.

Why does my Go select statement with time.After cause memory churn?

Using time.After in a select loop causes memory churn because it allocates a new timer and channel each iteration; replacing it with a reusable timer prevents this common concurrency anti-pattern.

How do I build a leak-free fan-out fan-in worker pool in Go?

Build leak-free fan-out/fan-in worker pools by applying structured concurrency rules to guarantee workers stop on context cancellation, propagate first errors correctly via errgroup, and avoid hidden shared memory.

Can I use this to audit existing Golang repositories for race conditions?

Yes, you can audit existing Golang repositories for race conditions and incorrect channel synchronization by applying these concurrency guardrails across repo-wide concurrency auditing workflows.