From c931d01f7233b8af7c29588b8ef656a967bd384c Mon Sep 17 00:00:00 2001 From: "daming.yang" Date: Mon, 10 Nov 2025 15:49:35 +0800 Subject: [PATCH] fix: avoid incrementing readErrCount for temporary errors and reset on successful read - Do not increment readErrCount for temporary errors such as timeouts, as they do not indicate actual connection failures. - Reset readErrCount after successful read operations to reflect the true health status of the connection. - This prevents readErrCount from growing due to normal timeout logic and provides a more accurate error state. --- conn.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/conn.go b/conn.go index 5161ef81..d93fed18 100644 --- a/conn.go +++ b/conn.go @@ -1009,7 +1009,14 @@ func (c *Conn) NextReader() (messageType int, r io.Reader, err error) { frameType, err := c.advanceFrame() if err != nil { c.readErr = hideTempErr(err) + if ne, ok := err.(net.Error); ok && (ne.Temporary() || ne.Timeout()) { + // temporary error, report it to the caller + return noFrame, nil, c.readErr + } break + } else { + // reset on successful read + c.readErrCount = 0 } if frameType == TextMessage || frameType == BinaryMessage {