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

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

## Root Cause

A nil pointer dereference occurs inside a goroutine, causing a panic that is not recovered. This can happen when a goroutine accesses a nil pointer without checking.

## Version Compatibility

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

## Workarounds

1. **Add a deferred recover inside the goroutine** (90% success)
   ```
   go func() {
    defer func() {
        if r := recover(); r != nil {
            log.Printf("Recovered in goroutine: %v", r)
        }
    }()
    // code that may panic
    var p *int
    *p = 42 // nil pointer dereference
}()
   ```
2. **Check for nil pointers before dereferencing** (95% success)
   ```
   if p != nil {
    *p = 42
} else {
    log.Println("nil pointer")
}
   ```

## Dead Ends

- **Adding a recover in the main goroutine only** — recover() only works within the same goroutine; panics in other goroutines cannot be recovered from the main goroutine. (95% fail)
- **Ignoring the panic and hoping the program continues** — An unhandled panic in any goroutine crashes the entire program. (99% fail)
