golang-concurrency-patterns

Implement Go concurrency patterns for context cancellation, errgroup, and worker pools.

68|19|Updated Nov 21, 2025
One-click install
npx skills add https://github.com/bobmatnyc/claude-mpm-skills --skill golang-concurrency-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-concurrency-patterns
Source: https://github.com/bobmatnyc/claude-mpm-skills/tree/main/toolchains/golang/concurrency
Command: npx skills add https://github.com/bobmatnyc/claude-mpm-skills --skill golang-concurrency-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers write robust and efficient concurrent Go applications by providing patterns to avoid common pitfalls like deadlocks, data races, and goroutine leaks.

Core Features & Use Cases

  • Context Propagation: Ensures cancellation signals are passed correctly through goroutines.
  • Error Handling: Utilizes errgroup for coordinated concurrent task execution and error propagation.
  • Resource Management: Demonstrates bounded concurrency using semaphores and worker pools to prevent resource exhaustion.
  • Use Case: When building a microservice that processes multiple requests concurrently, use these patterns to ensure that if one request fails, others are gracefully cancelled, and that the service doesn't spin up an unbounded number of goroutines.

Quick Start

Use the golang-concurrency-patterns skill to implement a bounded fan-out pattern for processing a list of items concurrently.

Frequently Asked Questions about golang-concurrency-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent goroutine leaks when using context for cancellation in Go?

To prevent goroutine leaks, propagate context cancellation signals through all goroutines so they exit gracefully when the context is done. This ensures concurrent tasks shut down cleanly without leaking resources.

What's the best way to handle errors when using errgroup for fan-out fan-in concurrency in golang?

The best way to handle errors with errgroup during fan-out fan-in is letting the group coordinate concurrent execution and capture the first error. This pattern automatically cancels remaining goroutines when a failure occurs, propagating the error back to the main caller.

How do I implement bounded parallelism using a worker pool in Go?

Implement bounded parallelism using worker pools or semaphores to limit active goroutines. This prevents resource exhaustion by ensuring your service only spins up a fixed number of concurrent workers to process items, maintaining stable memory and CPU usage.

Why does the race detector flag data races when sharing variables across goroutines?

The race detector flags data races because concurrent goroutines are accessing shared variables without proper synchronization. You can resolve these common race and deadlock pitfalls by applying mutexes or channels to protect memory access across concurrent operations.

Do I need to understand channels and mutexes before using these Go concurrency patterns?

Yes, you need prior understanding of Go's concurrency primitives like channels and mutexes. This Skill provides advanced, production-ready patterns for building reliable services and assumes you are already familiar with these foundational synchronization concepts.

When should I not use channels for synchronization in golang?

You should avoid using channels for simple state protection when a mutex provides clearer and more efficient synchronization. Understanding common race and deadlock pitfalls helps determine when mutexes or channels best fit your specific concurrency pattern.