# panic: runtime error: invalid memory address or nil pointer dereference

- **ID:** `go/goroutine-nil-pointer-deref`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A spawned goroutine dereferences a nil pointer, often because it captures a variable that hasn't been initialized yet, or a struct field accessed before assignment.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.18 | active | — | — |
| 1.20 | active | — | — |
| 1.22 | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Initialize all captured pointers before launching the goroutine, or pass values explicitly as function arguments: go func(cfg *Config) { ... }(cfg)
   ```
2. **** (88% success)
   ```
   Use errgroup and return errors instead of panicking; validate pointer non-nil at goroutine entry.
   ```

## Dead Ends

- **** — Treats symptom; the goroutine still operates on invalid state and may corrupt downstream logic. (70% fail)
- **** — Hides the bug; other goroutines still crash and root cause is masked. (80% fail)
