From 9e03cf65104cfff859ff880520ae3d068e12558e Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Fri, 26 Jan 2024 13:51:48 +0100 Subject: [PATCH] Reconfigure timeouts --- internal/config/types.go | 2 +- internal/universal/downloader.go | 2 +- pkg/http/client.go | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/config/types.go b/internal/config/types.go index a9c1ec2..354ccd8 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -172,7 +172,7 @@ func (z *ZurgConfig) EnableDownloadCache() bool { func (z *ZurgConfig) GetRealDebridTimeout() int { if z.RealDebridTimeout == 0 { - return 60 + return 10 } return z.RealDebridTimeout } diff --git a/internal/universal/downloader.go b/internal/universal/downloader.go index 5cbba8c..8a1075e 100644 --- a/internal/universal/downloader.go +++ b/internal/universal/downloader.go @@ -201,7 +201,7 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor } } - log.Debugf("Started serving file %s", unrestrict.Filename) + log.Infof("Started serving file %s%s", unrestrict.Filename, rangeLog) buf := make([]byte, cfg.GetNetworkBufferSize()) io.CopyBuffer(resp, download.Body, buf) diff --git a/pkg/http/client.go b/pkg/http/client.go index 2b73621..3032151 100644 --- a/pkg/http/client.go +++ b/pkg/http/client.go @@ -52,10 +52,8 @@ func (e *ApiErrorResponse) Error() string { func NewHTTPClient(token string, maxRetries int, timeoutSecs int, ensureIPv6Host bool, cfg config.ConfigInterface, log *logutil.Logger) *HTTPClient { client := HTTPClient{ bearerToken: token, - client: &http.Client{ - Timeout: time.Duration(timeoutSecs) * time.Second, - }, - maxRetries: maxRetries, + client: &http.Client{}, + maxRetries: maxRetries, backoff: func(attempt int) time.Duration { maxDuration := 60 backoff := int(math.Pow(2, float64(attempt))) @@ -110,7 +108,9 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, ensureIPv6Host log: log, } - var dialer proxy.Dialer = &net.Dialer{} + var dialer proxy.Dialer = &net.Dialer{ + Timeout: time.Duration(timeoutSecs) * time.Second, + } if proxyURLString := cfg.GetProxy(); proxyURLString != "" { proxyURL, err := url.Parse(proxyURLString) if err != nil { @@ -140,8 +140,9 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, ensureIPv6Host } client.client.Transport = &http.Transport{ - MaxIdleConns: maxConnections, - MaxConnsPerHost: maxConnections, + ResponseHeaderTimeout: time.Duration(timeoutSecs) * time.Second, + MaxIdleConns: 0, + MaxConnsPerHost: maxConnections, DialContext: func(ctx context.Context, network, address string) (net.Conn, error) { if ipv6Address, ok := client.ipv6.Get(address); ok { return dialer.Dial(network, ipv6Address)