Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add method to acknowledge expected/temporary read errors #912

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,8 +1007,9 @@ func (c *Conn) handleProtocolError(message string) error {
//
// Applications must break out of the application's read loop when this method
// returns a non-nil error value. Errors returned from this method are
// permanent. Once this method returns a non-nil error, all subsequent calls to
// this method return the same error.
// permanent, unless explicitly cleared using ClearReadError. Once this method
// returns a non-nil error, all subsequent calls to this method return the
// same error.
func (c *Conn) NextReader() (messageType int, r io.Reader, err error) {
// Close previous reader, only relevant for decompression.
if c.reader != nil {
Expand Down Expand Up @@ -1047,6 +1048,15 @@ func (c *Conn) NextReader() (messageType int, r io.Reader, err error) {
return noFrame, nil, c.readErr
}

// ClearReadError clears the read error state of the connection. This is
// primarily useful for handling expected errors such as read timeouts with
// non-blocking I/O. Applications must be careful to ensure errors are
// temporary before clearing them as not doing so will lead to busy loops.
func (c *Conn) ClearReadError() {
c.readErr = nil
c.readErrCount--
}

type messageReader struct{ c *Conn }

func (r *messageReader) Read(b []byte) (int, error) {
Expand Down