Skip to content

Commit

Permalink
channel: Improve error handling on a closed channel.
Browse files Browse the repository at this point in the history
The net package has grown a new net.ErrClosed that can be used to check for a
write on a closed connection. This allows us to get rid of the kludge we were
using parsing the error string.
  • Loading branch information
creachadair committed Sep 12, 2021
1 parent a1d23c5 commit 43e3392
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ package channel
import (
"errors"
"io"
"strings"
"net"
)

// A Channel represents the ability to transmit and receive data records. A
Expand All @@ -61,9 +61,7 @@ type Channel interface {
// IsErrClosing reports whether err is the internal error returned by a read
// from a pipe or socket that is closed. This is false for err == nil.
func IsErrClosing(err error) bool {
// That we must check the string here appears to be working as intended, or at least
// there is no intent to make it better. https://github.com/golang/go/issues/4373
return err != nil && strings.Contains(err.Error(), "use of closed network connection")
return err != nil && errors.Is(err, net.ErrClosed)
}

// A Framing converts a reader and a writer into a Channel with a particular
Expand Down

0 comments on commit 43e3392

Please sign in to comment.