diff --git a/cmd/server-mux.go b/cmd/server-mux.go index 1d7458d2c..e98741bb6 100644 --- a/cmd/server-mux.go +++ b/cmd/server-mux.go @@ -111,6 +111,8 @@ func (c *ConnMux) PeekProtocol() (string, error) { // Read - streams the ConnMux buffer when reset flag is activated, otherwise // streams from the incoming network connection func (c *ConnMux) Read(b []byte) (int, error) { + // Push read deadline + c.Conn.SetReadDeadline(time.Now().Add(defaultTCPReadTimeout)) return c.bufrw.Read(b) } @@ -176,6 +178,9 @@ type ListenerMuxAcceptRes struct { // Effective value of total keep alive comes upto 9 x 10 * time.Second = 1.5 Minutes. var defaultKeepAliveTimeout = 10 * time.Second // 10 seconds. +// Timeout to close connection when a client is not sending any data +var defaultTCPReadTimeout = 30 * time.Second + // newListenerMux listens and wraps accepted connections with tls after protocol peeking func newListenerMux(listener net.Listener, config *tls.Config) *ListenerMux { l := ListenerMux{ @@ -202,6 +207,9 @@ func newListenerMux(listener net.Listener, config *tls.Config) *ListenerMux { return } + // Enable Read timeout + conn.SetReadDeadline(time.Now().Add(defaultTCPReadTimeout)) + // Enable keep alive for each connection. conn.SetKeepAlive(true) conn.SetKeepAlivePeriod(defaultKeepAliveTimeout)