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

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

## Root Cause

A nil pointer is dereferenced inside a spawned goroutine. Because the panic happens in a child goroutine, it crashes the whole program and cannot be recovered from the parent.

## Version Compatibility

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

## Workarounds

1. **** (93% success)
   ```
   go func() {
    defer func() {
        if r := recover(); r != nil {
            log.Printf("goroutine panic: %v", r)
        }
    }()
    doWork()
}()
   ```
2. **** (90% success)
   ```
   if cfg == nil { return errors.New("nil cfg") }
go func(c Config) { use(c) }(*cfg)
   ```

## Dead Ends

- **** — recover only works in the panicking goroutine's own deferred function; the parent cannot catch it. (95% fail)
- **** — Race-dependent nil dereference only triggers under specific interleavings; production crashes intermittently. (80% fail)
