From 8317283ed30541f37572cb54acec865c08f24905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20Crespo?= Date: Thu, 25 Mar 2021 20:02:22 +0100 Subject: [PATCH] Unset WriteTimeout to allow streaming --- internal/api/api.go | 10 ++++++---- internal/collection/download.go | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/api/api.go b/internal/api/api.go index 4580eb6f..ead095af 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -85,10 +85,12 @@ func HTTPServer( } return &http.Server{ - Addr: config.Listen, - Handler: handler, - ReadTimeout: time.Second * 5, - WriteTimeout: time.Second * 10, + Addr: config.Listen, + Handler: handler, + ReadTimeout: time.Second * 5, + // WriteTimeout is set to 0 because we have streaming endpoints. + // https://github.com/golang/go/issues/16100#issuecomment-285573480 + WriteTimeout: 0, IdleTimeout: time.Second * 120, } } diff --git a/internal/collection/download.go b/internal/collection/download.go index 9ef8ef99..311bf71e 100644 --- a/internal/collection/download.go +++ b/internal/collection/download.go @@ -72,7 +72,7 @@ func (dp *downloadReverseProxy) modifyResponse(r *http.Response) error { func (dp *downloadReverseProxy) errorHandler(rw http.ResponseWriter, req *http.Request, err error) { rw.WriteHeader(http.StatusInternalServerError) fmt.Fprintf(rw, `{"message": "The operation failed unexpectedly. Contact the administrator for more details."}`) - dp.logger.Info("Download from Storage Service failed", "msg", err) + dp.logger.Info("Download from Storage Service failed", "msg", err.Error()) } func (p *downloadReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {