# error: http: superfluous response.WriteHeader call from ... (net/http: write tcp ...: write: broken pipe)

- **ID:** `go/http-server-timeout-write-broken-pipe`
- **Domain:** go
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

HTTP处理程序在已经写入响应体后又调用了WriteHeader，且客户端提前断开连接，导致写入操作返回broken pipe错误。

## Version Compatibility

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

## Workarounds

1. **** (85% success)
   ```
   if w.Written() { return } // 使用自定义ResponseWriter跟踪写入状态，避免重复调用WriteHeader
   ```
2. **** (90% success)
   ```
   在写入响应体前确保所有Header设置完成，并在WriteHeader后不再修改Header。
   ```

## Dead Ends

- **** — 忽略错误不会解决根本问题，客户端已断开，继续写入只会浪费资源并可能引发更多错误。 (90% fail)
- **** — net/http没有提供直接检查写入状态的方法，容易引入竞态条件。 (70% fail)
