go
network_error
ai_generated
true
错误:读取TCP连接192.168.1.10:8080->192.168.1.20:5432时,对端重置连接
error: read tcp 192.168.1.10:8080->192.168.1.20:5432: read: connection reset by peer
ID: go/http-connection-reset-by-peer
80%修复率
84%置信度
0证据数
2024-02-18首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.19 | active | — | — | — |
根因分析
对端服务器主动关闭了TCP连接,可能因超时、崩溃或防火墙干预。
English
对端服务器主动关闭了TCP连接,可能因超时、崩溃或防火墙干预。
解决方案
-
75% 成功率
实现连接池和重连逻辑: for { resp, err := client.Get(url) if err != nil { // 重新创建连接 client.CloseIdleConnections() continue } break } -
80% 成功率
设置合理的超时和重试: client := &http.Client{Timeout: 10 * time.Second} for i := 0; i < 3; i++ { resp, err := client.Get(url) if err == nil { break } time.Sleep(2 * time.Second) }
无效尝试
常见但无效的做法:
-
100% 失败
连接已无效,后续读写会失败。
-
70% 失败
keepalive不能防止对端重置,只能检测死连接。