ironsmile / nedomi

Highly performant HTTP reverse proxy with efficient caching of big files
GNU General Public License v3.0
81 stars 9 forks source link

Read timeout for netutils.timeoutConn in new Go versions does not work #229

Open ironsmile opened 5 years ago

ironsmile commented 5 years ago

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.