$npx -y skills add saifoelloh/golang-best-practices-skill --skill concurrency-safetyGo concurrency safety review. Use when checking goroutines, channels, race conditions, or synchronization. Detects goroutine leaks, deadlocks, race conditions, and unsafe channel operations.
| 1 | # Golang Concurrency Safety |
| 2 | |
| 3 | Expert-level concurrency safety review for Go applications. Detects common concurrency bugs that cause production failures, race conditions, deadlocks, and resource leaks. |
| 4 | |
| 5 | ## When to Apply |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Reviewing code with goroutines or channels |
| 9 | - Debugging race conditions or deadlocks |
| 10 | - Auditing concurrent data access |
| 11 | - Investigating goroutine leaks or memory issues |
| 12 | - Writing new concurrent code |
| 13 | - Preparing concurrent code for production |
| 14 | |
| 15 | ## Rule Categories by Priority |
| 16 | |
| 17 | | Priority | Count | Focus | |
| 18 | |----------|-------|-------| |
| 19 | | Critical | 5 | Prevents crashes, leaks, deadlocks | |
| 20 | | High | 4 | Correctness and reliability | |
| 21 | | Medium | 3 | Code quality and idioms | |
| 22 | |
| 23 | ## Rules Covered (12 total) |
| 24 | |
| 25 | ### Critical Issues (5) |
| 26 | |
| 27 | - `critical-goroutine-leak` - Goroutines must have exit conditions |
| 28 | - `critical-race-condition` - Protect shared state with mutex/channels |
| 29 | - `critical-channel-deadlock` - Ensure paired send/receive operations |
| 30 | - `critical-close-panic` - Sender closes channel, not receiver |
| 31 | - `critical-defer-in-loop` - Avoid defer in loops (resource leaks) |
| 32 | |
| 33 | ### High-Impact Patterns (4) |
| 34 | |
| 35 | - `high-goroutine-unbounded` - Limit concurrent goroutines (worker pool) |
| 36 | - `high-channel-not-closed` - Always close channels when done |
| 37 | - `high-loop-variable-capture` - Avoid closure over loop variables |
| 38 | - `high-waitgroup-mismatch` - Match Add() and Done() calls |
| 39 | |
| 40 | ### Medium Improvements (3) |
| 41 | |
| 42 | - `medium-directional-channels` - Use send/receive-only channels |
| 43 | - `medium-buffered-channel-size` - Choose appropriate buffer size |
| 44 | - `medium-select-default` - Avoid busy-wait with select |
| 45 | |
| 46 | ## How to Use |
| 47 | |
| 48 | ### For Code Review |
| 49 | |
| 50 | 1. Scan code for goroutine launches and channel operations |
| 51 | 2. Check against rules in priority order (Critical first) |
| 52 | 3. For each violation found, reference the specific rule file |
| 53 | 4. Provide exact line numbers and explanation |
| 54 | 5. Show corrected code example |
| 55 | |
| 56 | ### Accessing Detailed Rules |
| 57 | |
| 58 | Each rule file in `rules/` contains: |
| 59 | - Brief explanation of why it matters |
| 60 | - Detection criteria (how to spot the issue) |
| 61 | - Incorrect code example (❌ BAD) |
| 62 | - Correct code example (✅ GOOD) |
| 63 | - Impact assessment |
| 64 | - References |
| 65 | |
| 66 | **Example**: |
| 67 | ``` |
| 68 | rules/critical-goroutine-leak.md |
| 69 | rules/high-channel-not-closed.md |
| 70 | ``` |
| 71 | |
| 72 | ## Trigger Phrases |
| 73 | |
| 74 | This skill activates when you say: |
| 75 | - "Check for race conditions" |
| 76 | - "Review concurrency" |
| 77 | - "Find goroutine leaks" |
| 78 | - "Check for deadlocks" |
| 79 | - "Review channel usage" |
| 80 | - "Audit goroutine safety" |
| 81 | - "Check synchronization" |
| 82 | - "Review concurrent code" |
| 83 | |
| 84 | ## Common Patterns |
| 85 | |
| 86 | **Goroutine leak detection**: |
| 87 | ``` |
| 88 | Check this code for goroutine leaks |
| 89 | ``` |
| 90 | |
| 91 | **Race condition audit**: |
| 92 | ``` |
| 93 | Verify this concurrent code is safe |
| 94 | ``` |
| 95 | |
| 96 | **Channel safety review**: |
| 97 | ``` |
| 98 | Review channel usage for deadlocks |
| 99 | ``` |
| 100 | |
| 101 | ## Output Format |
| 102 | |
| 103 | When reviewing code, use this format: |
| 104 | |
| 105 | ``` |
| 106 | ## Critical Concurrency Issues: X |
| 107 | |
| 108 | ### [Rule Name] (Line Y) |
| 109 | **Issue**: Brief description |
| 110 | **Impact**: Race condition / Deadlock / Goroutine leak |
| 111 | **Fix**: Suggested correction |
| 112 | **Example**: |
| 113 | ```go |
| 114 | // Corrected code here |
| 115 | ``` |
| 116 | |
| 117 | ## High-Impact Patterns: X |
| 118 | |
| 119 | [Similar format for high priority items] |
| 120 | |
| 121 | ## Medium Improvements: X |
| 122 | |
| 123 | [Similar format for medium priority items] |
| 124 | ``` |
| 125 | |
| 126 | ## Philosophy |
| 127 | |
| 128 | Based on Katherine Cox-Buday's "Concurrency in Go": |
| 129 | |
| 130 | - **Concurrency is not parallelism** - Design for coordination, not just speed |
| 131 | - **Channels are for communication** - Use for passing ownership |
| 132 | - **Mutexes are for state** - Use for protecting shared memory |
| 133 | - **Always have exit conditions** - Every goroutine must be able to stop |
| 134 | - **Context is the standard** - Use context.Context for cancellation |
| 135 | |
| 136 | ## Related Skills |
| 137 | |
| 138 | - [golang-error-handling](../error-handling/SKILL.md) - For context propagation patterns |
| 139 | - [golang-clean-architecture](../clean-architecture/SKILL.md) - For usecase/repository concurrency patterns |
| 140 | |
| 141 | ## Notes |
| 142 | |
| 143 | - Rules are evidence-based from authoritative Go concurrency books |
| 144 | - All examples are tested and production-ready |
| 145 | - Detection patterns help identify issues systematically |
| 146 | - Focused exclusively on concurrency safety (not general Go patterns) |