mirror of
https://github.com/rclone/rclone.git
synced 2025-01-11 08:49:37 +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
|
// create a timeoutConn using the timeout
|
||||||
func newTimeoutConn(conn net.Conn, timeout time.Duration) *timeoutConn {
|
func newTimeoutConn(conn net.Conn, timeout time.Duration) (c *timeoutConn, err error) {
|
||||||
return &timeoutConn{
|
c = &timeoutConn{
|
||||||
Conn: conn,
|
Conn: conn,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
}
|
}
|
||||||
|
err = c.nudgeDeadline()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nudge the deadline for an idle timeout on by c.timeout if non-zero
|
// 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
|
// readOrWrite bytes doing idle timeouts
|
||||||
func (c *timeoutConn) readOrWrite(f func([]byte) (int, error), b []byte) (n int, err error) {
|
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)
|
n, err = f(b)
|
||||||
cerr := c.nudgeDeadline()
|
// Don't nudge if no bytes or an error
|
||||||
if err == nil && cerr != nil {
|
if n == 0 || err != nil {
|
||||||
err = cerr
|
return
|
||||||
}
|
}
|
||||||
return n, err
|
// Nudge the deadline on successful Read or Write
|
||||||
|
err = c.nudgeDeadline()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read bytes doing idle timeouts
|
// Read bytes doing idle timeouts
|
||||||
|
@ -20,7 +20,7 @@ func dialContextTimeout(ctx context.Context, network, address string, ci *fs.Con
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
return newTimeoutConn(c, ci.Timeout), nil
|
return newTimeoutConn(c, ci.Timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise the http.Transport for go1.7+
|
// 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 {
|
if err != nil {
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
return newTimeoutConn(c, ci.Timeout), nil
|
return newTimeoutConn(c, ci.Timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise the http.Transport for pre go1.7
|
// Initialise the http.Transport for pre go1.7
|
||||||
|
Loading…
Reference in New Issue
Block a user