# panic: http: panic serving 127.0.0.1:8080: runtime error: index out of range

- **ID:** `go/http-handler-panic-recovery`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

HTTP handler 中发生未捕获的 panic，导致服务器崩溃，默认 net/http 会恢复但记录日志。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.21 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   在 handler 内部使用 defer recover() 并记录日志
   ```
2. **** (90% success)
   ```
   使用中间件统一处理 panic，返回 500 错误
   ```

## Dead Ends

- **** — 连接会中断，且可能泄漏资源 (70% fail)
- **** — recover 必须在 panic 发生的 goroutine 中调用，handler 外无效 (90% fail)
