go network_error ai_generated true

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2024-02-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.19 active

Root Cause

对端服务器主动关闭了TCP连接,可能因超时、崩溃或防火墙干预。

generic

中文

对端服务器主动关闭了TCP连接,可能因超时、崩溃或防火墙干预。

Workarounds

  1. 75% success
    实现连接池和重连逻辑:
    for {
        resp, err := client.Get(url)
        if err != nil {
            // 重新创建连接
            client.CloseIdleConnections()
            continue
        }
        break
    }
  2. 80% success
    设置合理的超时和重试:
    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)
    }

Dead Ends

Common approaches that don't work:

  1. 100% fail

    连接已无效,后续读写会失败。

  2. 70% fail

    keepalive不能防止对端重置,只能检测死连接。