---
title: "waitgroup-add-inside-goroutine"
description: "Detect WaitGroup.Add calls inside newly started goroutines."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# waitgroup-add-inside-goroutine

**Default severity:** `error`

`WaitGroup.Add` must happen before starting the goroutine it accounts for.
Calling `Add` inside the goroutine races with `Wait`, which may observe a zero
counter and return too early.

## Bad

```go
go func() { group.Add(1); defer group.Done() }()
```

## Good

```go
group.Add(1)
go func() { defer group.Done() }()
```

Source: https://strider.gempir.com/analyzers/waitgroup-add-inside-goroutine/index.mdx
