Skip to content

Commit 69768b8

Browse files
authored
Merge pull request #72 from systemli/fix/silence-idle-connection-timeouts
Silence idle connection timeout logs in lookup and policy servers
2 parents 8a9ef38 + c8832a5 commit 69768b8

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

lookup.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
6-
"io"
77
"net"
88
"strings"
99
"sync"
@@ -77,12 +77,11 @@ func (s *LookupServer) HandleConnection(ctx context.Context, conn net.Conn) {
7777
// Read the request netstring
7878
requestBytes, err := decoder.Decode()
7979
if err != nil {
80-
// Check if this is a normal connection closure (EOF) or an actual error
81-
if err == io.EOF {
82-
logger.Debug("Client closed connection")
83-
} else {
84-
logger.Debug("Failed to decode request", zap.Error(err))
80+
var netErr net.Error
81+
if errors.As(err, &netErr) && netErr.Timeout() {
82+
return
8583
}
84+
logger.Debug("Failed to decode request", zap.Error(err))
8685
return
8786
}
8887
request := string(requestBytes)

policy.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"errors"
77
"fmt"
8-
"io"
98
"net"
109
"strings"
1110
"sync"
@@ -62,9 +61,11 @@ func (p *PolicyServer) HandleConnection(ctx context.Context, conn net.Conn) {
6261

6362
request, err := p.readRequest(reader)
6463
if err != nil {
65-
if !errors.Is(err, io.EOF) {
66-
logger.Debug("Failed to read policy request", zap.Error(err))
64+
var netErr net.Error
65+
if errors.As(err, &netErr) && netErr.Timeout() {
66+
return
6767
}
68+
logger.Debug("Failed to read policy request", zap.Error(err))
6869
return
6970
}
7071

0 commit comments

Comments
 (0)