nedomi
nedomi copied to clipboard
Read timeout for netutils.timeoutConn in new Go versions does not work
In current versions of Go (1.11, 1.12) startBackgroundRead
in server.go always sets ReadDeadline to the zero time. The code in question:
func (cr *connReader) startBackgroundRead() {
cr.lock()
defer cr.unlock()
if cr.inRead {
panic("invalid concurrent Body.Read call")
}
if cr.hasByte {
return
}
cr.inRead = true
cr.conn.rwc.SetReadDeadline(time.Time{}) // <----- Line in question
go cr.backgroundRead()
}
This makes the the ReadDeadline to be some strange number in our implementation, possibly negative. Which the TCP server treats as "I should close this connection". This in turn makes all such connections unusable.
We should make sure there is no possible code path where SetDeadline, SetReadDeadline and SetWriteDeadline of our timeoutConn would case the connection to be closed prematurely.