diff options
| author | chrislu <chris.lu@gmail.com> | 2021-12-29 22:44:39 -0800 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2021-12-29 22:44:39 -0800 |
| commit | fb434318e36ac8e78ab304bfd5421f110c10bdf1 (patch) | |
| tree | 4c53c9463f0486a342ab0cc7d4a26c56b9a86ab3 /weed/util/net_timeout.go | |
| parent | 5788bf2270c2158798d1ff48c5e7145e8899e1a3 (diff) | |
| download | seaweedfs-fb434318e36ac8e78ab304bfd5421f110c10bdf1.tar.xz seaweedfs-fb434318e36ac8e78ab304bfd5421f110c10bdf1.zip | |
dynamically adjust connection timeout
better fix for https://github.com/chrislusf/seaweedfs/issues/2541
Diffstat (limited to 'weed/util/net_timeout.go')
| -rw-r--r-- | weed/util/net_timeout.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/weed/util/net_timeout.go b/weed/util/net_timeout.go index e8075c297..f1ae9016d 100644 --- a/weed/util/net_timeout.go +++ b/weed/util/net_timeout.go @@ -36,11 +36,13 @@ type Conn struct { ReadTimeout time.Duration WriteTimeout time.Duration isClosed bool + bytesRead int64 + bytesWritten int64 } func (c *Conn) Read(b []byte) (count int, e error) { if c.ReadTimeout != 0 { - err := c.Conn.SetReadDeadline(time.Now().Add(c.ReadTimeout)) + err := c.Conn.SetReadDeadline(time.Now().Add(c.ReadTimeout * time.Duration(c.bytesRead/40000+1))) if err != nil { return 0, err } @@ -48,6 +50,7 @@ func (c *Conn) Read(b []byte) (count int, e error) { count, e = c.Conn.Read(b) if e == nil { stats.BytesIn(int64(count)) + c.bytesRead += int64(count) } return } @@ -55,7 +58,7 @@ func (c *Conn) Read(b []byte) (count int, e error) { func (c *Conn) Write(b []byte) (count int, e error) { if c.WriteTimeout != 0 { // minimum 4KB/s - err := c.Conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout * time.Duration(len(b)/40000+1))) + err := c.Conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout * time.Duration(c.bytesWritten/40000+1))) if err != nil { return 0, err } @@ -63,6 +66,7 @@ func (c *Conn) Write(b []byte) (count int, e error) { count, e = c.Conn.Write(b) if e == nil { stats.BytesOut(int64(count)) + c.bytesWritten += int64(count) } return } |
