Skip to content

Commit 02e4f5d

Browse files
set the timeout early
1 parent 2cb8f8c commit 02e4f5d

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

server/listener.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (h *Handler) handleConnection(conn net.Conn) error {
9696

9797
scanner := bufio.NewScanner(conn)
9898

99-
var startOfEOF time.Time
99+
var startOfEOF time.Time = time.Time{} // start the counter when the connection is opened so that we can track EOF wait time correctly
100100

101101
for {
102102
if !scanner.Scan() {
@@ -107,15 +107,13 @@ func (h *Handler) handleConnection(conn net.Conn) error {
107107

108108
if startOfEOF.IsZero() {
109109
startOfEOF = time.Now()
110-
} else {
111-
if time.Since(startOfEOF) > h.maxEOFWait {
112-
log.Println("Connection timed out. Closing connection")
113-
return nil
114-
}
110+
} else if time.Since(startOfEOF) > h.maxEOFWait {
111+
log.Println("Connection timed out. Closing connection")
112+
return nil
115113
}
116-
117114
continue
118115
}
116+
119117
startOfEOF = time.Time{}
120118
line := scanner.Text()
121119
if line == "" {

0 commit comments

Comments
 (0)