Silence net.ErrClosed errors
This commit is contained in:
parent
7e6ce23dac
commit
c8a54235d0
6
conn.go
6
conn.go
@ -194,7 +194,7 @@ func newConn(srv *Server, ic ircConn, options *connOptions) *conn {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err := c.conn.Close(); err != nil {
|
||||
if err := c.conn.Close(); err != nil && !isErrClosed(err) {
|
||||
c.logger.Printf("failed to close connection: %v", err)
|
||||
} else {
|
||||
c.logger.Printf("connection closed")
|
||||
@ -232,7 +232,9 @@ func (c *conn) Close() error {
|
||||
|
||||
func (c *conn) ReadMessage() (*irc.Message, error) {
|
||||
msg, err := c.conn.ReadMessage()
|
||||
if err != nil {
|
||||
if isErrClosed(err) {
|
||||
return nil, io.EOF
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
11
net_go113.go
Normal file
11
net_go113.go
Normal file
@ -0,0 +1,11 @@
|
||||
// +build !go1.16
|
||||
|
||||
package soju
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func isErrClosed(err error) bool {
|
||||
return err != nil && strings.Contains(err.Error(), "use of closed network connection")
|
||||
}
|
12
net_go116.go
Normal file
12
net_go116.go
Normal file
@ -0,0 +1,12 @@
|
||||
// +build go1.16
|
||||
|
||||
package soju
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
)
|
||||
|
||||
func isErrClosed(err error) bool {
|
||||
return errors.Is(err, net.ErrClosed)
|
||||
}
|
Loading…
Reference in New Issue
Block a user