Skip to content

Commit

Permalink
Use the new net.ErrClosed (golang/go#4373)
Browse files Browse the repository at this point in the history
  • Loading branch information
r4g3baby committed Mar 31, 2021
1 parent 7aab21b commit ed7f7d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
9 changes: 3 additions & 6 deletions pkg/server/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,7 @@ func (conn *Connection) handlePostPacketWrite(packet protocol.Packet) error {
switch packet.(type) {
case *packets.PacketStatusOutPong:
if err := conn.Close(); err != nil {
// See https://github.com/golang/go/issues/4373 for info.
if !strings.Contains(err.Error(), "use of closed network connection") {
if !errors.Is(err, net.ErrClosed) {
return err
}
}
Expand All @@ -430,8 +429,7 @@ func (conn *Connection) handlePostPacketWrite(packet protocol.Packet) error {
switch p := packet.(type) {
case *packets.PacketLoginOutDisconnect:
if err := conn.DelayedClose(250 * time.Millisecond); err != nil {
// See https://github.com/golang/go/issues/4373 for info.
if !strings.Contains(err.Error(), "use of closed network connection") {
if !errors.Is(err, net.ErrClosed) {
return err
}
}
Expand All @@ -444,8 +442,7 @@ func (conn *Connection) handlePostPacketWrite(packet protocol.Packet) error {
switch packet.(type) {
case *packets.PacketPlayOutDisconnect:
if err := conn.DelayedClose(250 * time.Millisecond); err != nil {
// See https://github.com/golang/go/issues/4373 for info.
if !strings.Contains(err.Error(), "use of closed network connection") {
if !errors.Is(err, net.ErrClosed) {
return err
}
}
Expand Down
9 changes: 3 additions & 6 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ func (server *Server) Start() error {
default:
client, err := listener.Accept()
if err != nil {
// See https://github.com/golang/go/issues/4373 for info.
if !strings.Contains(err.Error(), "use of closed network connection") {
if !errors.Is(err, net.ErrClosed) {
log.Warn().Err(err).Msg("error occurred while accepting s new connection")
}
continue
Expand Down Expand Up @@ -173,8 +172,7 @@ func (server *Server) handleClient(conn net.Conn) {
connection := NewConnection(conn, server)
for {
if err := connection.ReadPacket(); err != nil {
// See https://github.com/golang/go/issues/4373 for info.
if !strings.Contains(err.Error(), "use of closed network connection") {
if !errors.Is(err, net.ErrClosed) {
log.Error().Err(err).Stringer("connection", connection.RemoteAddr()).Msg("got error during packet read")
// todo: should we disconnect?
}
Expand All @@ -183,8 +181,7 @@ func (server *Server) handleClient(conn net.Conn) {
}

if err := connection.Close(); err != nil {
// See https://github.com/golang/go/issues/4373 for info.
if !strings.Contains(err.Error(), "use of closed network connection") {
if !errors.Is(err, net.ErrClosed) {
log.Warn().Err(err).Stringer("connection", connection.RemoteAddr()).Msg("got error while closing connection")
return
}
Expand Down

0 comments on commit ed7f7d2

Please sign in to comment.