Skip to content

Commit

Permalink
somehow Read timeouts are not matched by `errors.Is(err, os.ErrDeadli…
Browse files Browse the repository at this point in the history
…neExceeded)`
  • Loading branch information
aldas committed Jul 27, 2023
1 parent de1ce46 commit 37ada3c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io"
"log"
"net"
"os"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -215,6 +214,11 @@ func (s *Server) trackConn(c *connection, isAdd bool) {
}
}

func isTimeout(err error) bool {
var terr interface{ Timeout() bool }
return errors.As(err, &terr) && terr.Timeout()
}

func (c *connection) handle(ctx context.Context) {
cCtx, cCancel := context.WithCancel(ctx)
defer cCancel()
Expand Down Expand Up @@ -244,7 +248,7 @@ func (c *connection) handle(ctx context.Context) {
if debugRawRead {
rrt.Read(received[0:n], n, err)
}
if err != nil && !os.IsTimeout(err) {
if err != nil && !isTimeout(err) {
if !errors.Is(err, io.EOF) {
c.onErrorFunc(err)
}
Expand Down

0 comments on commit 37ada3c

Please sign in to comment.