From 5788bf2270c2158798d1ff48c5e7145e8899e1a3 Mon Sep 17 00:00:00 2001 From: chrislu Date: Wed, 29 Dec 2021 22:21:02 -0800 Subject: [PATCH] s3: increase timeout limit https://github.com/chrislusf/seaweedfs/issues/2541 --- weed/command/s3.go | 2 +- weed/s3api/s3api_object_handlers.go | 4 +++- weed/util/http_util.go | 23 +++++++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/weed/command/s3.go b/weed/command/s3.go index ee726fcec..679a4ae45 100644 --- a/weed/command/s3.go +++ b/weed/command/s3.go @@ -192,7 +192,7 @@ func (s3opt *S3Options) startS3Server() bool { httpS := &http.Server{Handler: router} listenAddress := fmt.Sprintf("%s:%d", *s3opt.bindIp, *s3opt.port) - s3ApiListener, err := util.NewListener(listenAddress, time.Duration(10)*time.Second) + s3ApiListener, err := util.NewListener(listenAddress, time.Duration(30)*time.Second) if err != nil { glog.Fatalf("S3 API Server listener on %s error: %v", listenAddress, err) } diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go index d78332395..b06f540fb 100644 --- a/weed/s3api/s3api_object_handlers.go +++ b/weed/s3api/s3api_object_handlers.go @@ -364,7 +364,9 @@ func passThroughResponse(proxyResponse *http.Response, w http.ResponseWriter) (s statusCode = proxyResponse.StatusCode } w.WriteHeader(statusCode) - io.Copy(w, proxyResponse.Body) + if n, err := io.Copy(w, proxyResponse.Body); err != nil { + glog.V(1).Infof("passthrough response read %d bytes: %v", n, err) + } return statusCode } diff --git a/weed/util/http_util.go b/weed/util/http_util.go index 7bd6758eb..34765d68e 100644 --- a/weed/util/http_util.go +++ b/weed/util/http_util.go @@ -392,11 +392,30 @@ func ReadUrlAsReaderCloser(fileUrl string, rangeHeader string) (io.ReadCloser, e } 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 }