@@ -22,6 +22,9 @@ import (
22
22
"fmt"
23
23
"net"
24
24
"syscall"
25
+ "time"
26
+
27
+ "github.com/minio/minio/internal/deadlineconn"
25
28
)
26
29
27
30
type acceptResult struct {
@@ -32,6 +35,7 @@ type acceptResult struct {
32
35
33
36
// httpListener - HTTP listener capable of handling multiple server addresses.
34
37
type httpListener struct {
38
+ opts TCPOptions
35
39
tcpListeners []* net.TCPListener // underlying TCP listeners.
36
40
acceptCh chan acceptResult // channel where all TCP listeners write accepted connection.
37
41
ctx context.Context
@@ -74,7 +78,8 @@ func (listener *httpListener) Accept() (conn net.Conn, err error) {
74
78
select {
75
79
case result , ok := <- listener .acceptCh :
76
80
if ok {
77
- return result .conn , result .err
81
+ return deadlineconn .New (result .conn ).
82
+ WithReadDeadline (listener .opts .ClientReadTimeout ), result .err
78
83
}
79
84
case <- listener .ctx .Done ():
80
85
}
@@ -119,9 +124,10 @@ func (listener *httpListener) Addrs() (addrs []net.Addr) {
119
124
120
125
// TCPOptions specify customizable TCP optimizations on raw socket
121
126
type TCPOptions struct {
122
- UserTimeout int // this value is expected to be in milliseconds
123
- Interface string // this is a VRF device passed via `--interface` flag
124
- Trace func (msg string ) // Trace when starting.
127
+ UserTimeout int // this value is expected to be in milliseconds
128
+ ClientReadTimeout time.Duration // When the net.Conn is idle for more than ReadTimeout duration, we close the connection on the client proactively.
129
+ Interface string // this is a VRF device passed via `--interface` flag
130
+ Trace func (msg string ) // Trace when starting.
125
131
}
126
132
127
133
// newHTTPListener - creates new httpListener object which is interface compatible to net.Listener.
@@ -173,6 +179,7 @@ func newHTTPListener(ctx context.Context, serverAddrs []string, opts TCPOptions)
173
179
listener = & httpListener {
174
180
tcpListeners : tcpListeners ,
175
181
acceptCh : make (chan acceptResult , len (tcpListeners )),
182
+ opts : opts ,
176
183
}
177
184
listener .ctx , listener .ctxCanceler = context .WithCancel (ctx )
178
185
if opts .Trace != nil {
0 commit comments