mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 15:38:57 +01:00
fshttp: fix idle timeouts for HTTP connections #2057
Now we only nudge on the idle timeout after a successful Read or Write which returns some bytes and no errors.
This commit is contained in:
parent
9b800d7184
commit
a5c3bcc9c7
@ -49,11 +49,13 @@ type timeoutConn struct {
|
||||
}
|
||||
|
||||
// create a timeoutConn using the timeout
|
||||
func newTimeoutConn(conn net.Conn, timeout time.Duration) *timeoutConn {
|
||||
return &timeoutConn{
|
||||
func newTimeoutConn(conn net.Conn, timeout time.Duration) (c *timeoutConn, err error) {
|
||||
c = &timeoutConn{
|
||||
Conn: conn,
|
||||
timeout: timeout,
|
||||
}
|
||||
err = c.nudgeDeadline()
|
||||
return
|
||||
}
|
||||
|
||||
// Nudge the deadline for an idle timeout on by c.timeout if non-zero
|
||||
@ -67,16 +69,14 @@ func (c *timeoutConn) nudgeDeadline() (err error) {
|
||||
|
||||
// readOrWrite bytes doing idle timeouts
|
||||
func (c *timeoutConn) readOrWrite(f func([]byte) (int, error), b []byte) (n int, err error) {
|
||||
err = c.nudgeDeadline()
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
n, err = f(b)
|
||||
cerr := c.nudgeDeadline()
|
||||
if err == nil && cerr != nil {
|
||||
err = cerr
|
||||
// Don't nudge if no bytes or an error
|
||||
if n == 0 || err != nil {
|
||||
return
|
||||
}
|
||||
return n, err
|
||||
// Nudge the deadline on successful Read or Write
|
||||
err = c.nudgeDeadline()
|
||||
return
|
||||
}
|
||||
|
||||
// Read bytes doing idle timeouts
|
||||
|
@ -20,7 +20,7 @@ func dialContextTimeout(ctx context.Context, network, address string, ci *fs.Con
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
return newTimeoutConn(c, ci.Timeout), nil
|
||||
return newTimeoutConn(c, ci.Timeout)
|
||||
}
|
||||
|
||||
// Initialise the http.Transport for go1.7+
|
||||
|
@ -18,7 +18,7 @@ func dialTimeout(network, address string, ci *fs.ConfigInfo) (net.Conn, error) {
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
return newTimeoutConn(c, ci.Timeout), nil
|
||||
return newTimeoutConn(c, ci.Timeout)
|
||||
}
|
||||
|
||||
// Initialise the http.Transport for pre go1.7
|
||||
|
Loading…
Reference in New Issue
Block a user