# panic: runtime error: invalid memory address or nil pointer dereference (in goroutine)

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

## Root Cause

A goroutine attempted to dereference a nil pointer. This often occurs when a shared pointer is set to nil by another goroutine, or when a struct field is not initialized before being used in a goroutine.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.0+ | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   var mu sync.Mutex
mu.Lock()
if ptr != nil {
    // use ptr
}
mu.Unlock()
   ```
2. **** (90% success)
   ```
   go func(v MyStruct) {
    // use v
}(*ptr)
   ```

## Dead Ends

- **** — The pointer may become nil between the check and the dereference due to a race condition. Nil checks are not atomic with the dereference. (85% fail)
- **** — Recovering prevents the crash but leaves the program in an inconsistent state; the root cause remains. (90% fail)
