server/mux: Close the connection even if buffer.Flush() returns error. (#3599)

It is possible that buf.Flush() might return an error, leading to a
potential leak in active sockets.
This commit is contained in:
Harshavardhana 2017-01-19 11:19:57 -08:00 committed by GitHub
parent 9e1f1b50e0
commit a17f1e875c

View File

@ -108,10 +108,12 @@ func (c *ConnMux) Read(b []byte) (int, error) {
// Close the connection. // Close the connection.
func (c *ConnMux) Close() (err error) { func (c *ConnMux) Close() (err error) {
if err = c.bufrw.Flush(); err != nil { // Make sure that we always close a connection,
return err // even if the bufioWriter flush sends an error.
} defer c.Conn.Close()
return c.Conn.Close()
// Flush and write to the connection.
return c.bufrw.Flush()
} }
// ListenerMux wraps the standard net.Listener to inspect // ListenerMux wraps the standard net.Listener to inspect