# panic: http: Server closed

- **ID:** `go/httptest-server-close-panic`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

调用 httptest.Server.Close() 后，仍有 goroutine 尝试向该服务器发送请求，导致底层连接被关闭，触发 panic。

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   使用 sync.WaitGroup 确保所有请求完成后关闭服务器
   ```
2. **** (85% success)
   ```
   设置 server.Config.ReadTimeout 和 WriteTimeout，避免请求无限期挂起
   ```

## Dead Ends

- **** — httptest.Server 关闭后不可复用，连接池中的连接已失效，重试只会导致相同 panic (90% fail)
- **** — defer 在函数结束时才执行，但未等待所有 goroutine 结束，仍可能触发 panic (75% fail)
- **** — panic 是致命的，捕获后程序状态可能不一致，且掩盖了真正的并发问题 (60% fail)
