From 2c5b038df28af21f52d8535de9989884efd693c8 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Mon, 5 Feb 2024 18:32:31 +0400 Subject: [PATCH] Set HTTP client timeout to 30 seconds (#153) * Set HTTP client timeout to 30 seconds * Add an explanation for why we set http.Server's Timeout --- pkg/client/client.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/client/client.go b/pkg/client/client.go index 1937f1c..51a1d01 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -20,6 +20,7 @@ import ( "net/http" "net/url" "nhooyr.io/websocket" + "time" ) var ( @@ -77,6 +78,11 @@ func New(opts ...Option) (*Client, error) { // Instantiate the HTTP client client.httpClient = &http.Client{ + // The default is zero, which means no timeout, which means that + // the requests may hang indefinitely. See [1] for more details. + // + // [1]: https://github.com/cirruslabs/orchard/issues/152#issuecomment-1927091747 + Timeout: 30 * time.Second, Transport: &http.Transport{ TLSClientConfig: client.tlsConfig, },