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
This commit is contained in:
Nikolay Edigaryev 2024-02-05 18:32:31 +04:00 committed by GitHub
parent 5da967b88c
commit 2c5b038df2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -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,
},