Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

go-concurrency

/go-concurrency

Pomaga pisać i przeglądać współbieżny kod Go: goroutines, kanały, errgroup, anulowanie przez context i wycieki goroutines.

Repozytorium
agents ↗
Licencja
MIT
Ostatnia zmiana repozytorium
12.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
8
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 12.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pomaga pisać i przeglądać współbieżny kod Go: goroutines, kanały, errgroup, anulowanie przez context i wycieki goroutines.

Oryginalny opis (EN)

Use when writing or reviewing Go concurrency — goroutines, channels, errgroup, context cancellation, or goroutine leaks. Not for sequential idioms (go-core-idioms).

Jak działa

  1. Agent Workflow (MANDATORY)
  2. Overview
  3. Critical Rules
  4. Architecture
  5. Reference Guide
  6. Quick Reference
  7. Best Practices
Sekcje z nagłówków SKILL.md, w oryginale · 127 linii, 615 słów
Podgląd SKILL.md
---
name: go-concurrency
description: Use when writing or reviewing Go concurrency — goroutines, channels, errgroup, context cancellation, or goroutine leaks. Not for sequential idioms (go-core-idioms).
versions:
  go: "1.27"
  golang.org/x/sync: "latest"
user-invocable: false
references: references/goroutines-channels.md, references/errgroup.md, references/context-propagation.md, references/goroutine-leaks.md, references/templates/errgroup-patterns.md, references/templates/worker-pool.md
related-skills: go-core-idioms, solid-go
---

<objective>
Covers Go concurrency for Go 1.27: goroutines and channels, golang.org/x/sync/errgroup,
context propagation and cancellation, sync.WaitGroup vs channels, the -race detector,
and diagnosing goroutine leaks (including the goroutineleak profile, GA in 1.27). Does not
cover sequential error handling, slog, generics, or interface style (see
go-core-idioms), non-Go languages, or framework-specific code.
</objective>

# Go Concurrency

Goroutines, channels, `context`, and `errgroup` for Go 1.27 — plus the number-one
documented pitfall: **leaking goroutines on an unbuffered channel + early return.**

## Agent Workflow (MANDATORY)

Before ANY implementation, spawn 3 agents in parallel, one `Agent` call each with a `name`:

1. **fuse-ai-pilot:explore-codebase** - Map existing goroutine/channel/context usage
2. **fuse-ai-pilot:research-expert** - Verify errgroup/context docs via Context7/Exa
3. **mcp__context7__query-docs** - Confirm `golang.org/x/sync/errgroup` signatures

After implementation, run **fuse-ai-pilot:sniper** for validation, and run tests
with `go test -race ./...`.

---

## Overview

| Feature | Description |
|---------|-------------|
| **Goroutines & channels** | Lightweight concurrency + typed communication |
| **errgroup** | Parallelism + error aggregation + context cancellation |
| **context** | First param, propagated strictly, carries cancellation/deadline |
| **WaitGroup vs channels** | Counting-only vs result/error passing |
| **Race detector** | `-race` in tests/CI to catch data races |
| **Leak profile (GA 1.27)** | `pprof.Lookup("goroutineleak")` / `/debug/pprof/goroutineleak` — no GOEXPERIMENT needed |

---

## Critical Rules

1. **`context.Context` is the first parameter** - named `ctx`, never stored in a struct
2. **Every started goroutine must be able to exit** - or it leaks (see rule 4)
3. **Prefer `errgroup` for fan-out with errors** - it handles wait + first error + cancel
4. **Unbuffered channel + early return = leak** - senders block forever; buffer or drain
5. **Test with `-race`** - a passing test without `-race` proves nothing about races

---

## Architecture

```
internal/
├── fetch/
│   ├── fetch.go        # errgroup.WithContext fan-out, bounded by SetLimit
│   └── worker.go       # worker pool: fixed goroutines drain a jobs channel
└── pipeline/
    └── stage.go        # ctx-cancellable stages, buffered hand-off channels
```

→ See [errgroup-patterns.md](references/templates/errgroup-patterns.md) for full example

---

## Reference Guide

### Concepts

| Topic | Reference | When to Consult |
|-------|-----------|-----------------|
| **Goroutines & channels** | [goroutines-channels.md](references/goroutines-channels.md) | Buffered vs not, select, WaitGroup vs channels |
| **errgroup** | [errgroup.md](references/errgroup.md) | Fan-out, error aggregation, SetLimit, TryGo |
| **context** | [context-propagation.md](references/context-propagation.md) | Cancellation, deadlines, propagation rules |
| **Goroutine leaks** | [goroutine-leaks.md](references/goroutine-leaks.md) | The #1 pitfall + the goroutineleak profile (GA 1.27) |

### Templates

| Template | When to Use |
|----------|-------------|
| [errgroup-patterns.md](references/templates/errgroup-patterns.md) | Bounded parallel work with error handling |
| [worker-pool.md](references/templates/worker-pool.md) | Fixed workers draining a job queue |

---

## Quick Reference

### Parallel work with errgroup

```go
g, ctx := errgroup.WithContext(ctx)
g.SetLimit(8) // bound concurrency
for _, u := range urls {
    g.Go(func() error { return fetch(ctx, u) })
}
if err := g.Wait(); err != nil { // first non-nil error; cancels ctx
    return err
}
```

→ See [errgroup.md](references/errgroup.md)

### Avoid the leak (buffer so senders never block)

```go
ch := make(chan result, len(items)) // buffered → early return can't strand senders
```

→ See [goroutine-leaks.md](references/goroutine-leaks.md)

---

## Best Practices

### DO
- Pass `ctx` first and thread it through every blocking call
- Reach for `errgroup` before hand-rolling `WaitGroup` + error channels
- Buffer result channels to the number of senders, or fully drain them
- Run `go test -race`; check the `goroutineleak` profile in CI (GA in 1.27; the
  1.26 `GOEXPERIMENT=goroutineleakprofile` flag is deleted)

### DON'T
- Return early from a fan-out while goroutines still block on an unbuffered channel
- Store a `context.Context` in a struct field
- Use a bare `sync.WaitGroup` when goroutines return errors (use `errgroup`)
- Assume tests are race-free without the `-race` flag
Pliki w paczce (8)
  • .gitkeep 1 KB
  • SKILL.md 5 KB
  • references/context-propagation.md 3 KB
  • references/errgroup.md 3 KB
  • references/goroutine-leaks.md 4 KB
  • references/goroutines-channels.md 3 KB
  • references/templates/errgroup-patterns.md 2 KB
  • references/templates/worker-pool.md 2 KB

Wersje

RepozytoriumWynikLicencja
Ta strona · fusengine/agents100MIT
h0rn3t/golang-skills100Apache-2.0
muratmirgun/gophers100MIT
muratmirgun/gophers100MIT
cxuu/golang-skills100Apache-2.0
TheBushidoCollective/han95Apache-2.0
Amey-Thakur/AI-SKILLS90MIT

Migawka bazy z 28.10.2026 · wersja paczki 4cae1add6b12 (skrót SHA-256 całej paczki)

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100golang-concurrency
    Pisze bezpieczny współbieżny kod Go z goroutines, kanałami i context.
  • 100go-concurrency-practice
    Egzekwuje praktyczne reguły współbieżności w Go z książki „100 Go Mistakes” przy pisaniu i przeglądzie kodu: propagację context, wycieki goroutines, wyścigi danych i deadlocki.
  • 100go-expert
    Wspiera pracę z Go 1.22+ na poziomie eksperckim: współbieżność, biblioteka standardowa, goroutines, kanały, anulowanie przez context i serwery HTTP gotowe na produkcję.
  • 100go-concurrency-review
    Recenzuje i wdraża bezpieczne wzorce współbieżności w Go: goroutines, kanały, prymitywy sync, propagacja kontekstu, cykl życia goroutines, wyścigi danych i potoki producent-konsument.
  • 100go-expert
    Pomaga pisać i recenzować backendy w Go: API HTTP na routerze stdlib Go 1.22, błędy opakowywania i anulowania kontekstu, cykl życia goroutines z errgroup oraz warstwy danych pgx i sqlc.
  • 100go-concurrency-patterns
    Uczy współbieżności w Go: goroutines, kanały, prymitywy sync i context, przy budowie aplikacji, worker pools i diagnozowaniu wyścigów danych.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.