diff options
Diffstat (limited to 'weed/util')
| -rw-r--r-- | weed/util/constants.go | 2 | ||||
| -rw-r--r-- | weed/util/http_util.go | 23 | ||||
| -rw-r--r-- | weed/util/net_timeout.go | 8 |
3 files changed, 28 insertions, 5 deletions
diff --git a/weed/util/constants.go b/weed/util/constants.go index 8e178bc4a..255d00722 100644 --- a/weed/util/constants.go +++ b/weed/util/constants.go @@ -5,7 +5,7 @@ import ( ) var ( - VERSION_NUMBER = fmt.Sprintf("%.02f", 2.82) + VERSION_NUMBER = fmt.Sprintf("%.02f", 2.83) VERSION = sizeLimit + " " + VERSION_NUMBER COMMIT = "" ) diff --git a/weed/util/http_util.go b/weed/util/http_util.go index e658ab66b..8b66c6dc1 100644 --- a/weed/util/http_util.go +++ b/weed/util/http_util.go @@ -405,11 +405,30 @@ func ReadUrlAsReaderCloser(fileUrl string, jwt string, rangeHeader string) (io.R } func CloseResponse(resp *http.Response) { - io.Copy(io.Discard, resp.Body) + reader := &CountingReader{reader: resp.Body} + io.Copy(io.Discard, reader) resp.Body.Close() + if reader.BytesRead > 0 { + glog.V(1).Infof("response leftover %d bytes", reader.BytesRead) + } } func CloseRequest(req *http.Request) { - io.Copy(io.Discard, req.Body) + reader := &CountingReader{reader: req.Body} + io.Copy(io.Discard, reader) req.Body.Close() + if reader.BytesRead > 0 { + glog.V(1).Infof("request leftover %d bytes", reader.BytesRead) + } +} + +type CountingReader struct { + reader io.Reader + BytesRead int +} + +func (r *CountingReader) Read(p []byte) (n int, err error) { + n, err = r.reader.Read(p) + r.BytesRead += n + return n, err } 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 } |
