fix(registry): set default HTTP client timeout for registry client

The default http.Client had no Timeout, so an unresponsive registry could
hang helm registry operations indefinitely.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
pull/32291/head
Sebastien Tardif 3 months ago
parent f3d68cdbea
commit 0d3a331073

@ -30,6 +30,7 @@ import (
"os" "os"
"sort" "sort"
"strings" "strings"
"time"
"github.com/Masterminds/semver/v3" "github.com/Masterminds/semver/v3"
"github.com/opencontainers/image-spec/specs-go" "github.com/opencontainers/image-spec/specs-go"
@ -97,6 +98,8 @@ func NewClient(options ...ClientOption) (*Client, error) {
} }
if client.httpClient == nil { if client.httpClient == nil {
client.httpClient = &http.Client{ client.httpClient = &http.Client{
// Bound registry operations so an unresponsive registry cannot hang forever.
Timeout: 30 * time.Second,
Transport: NewTransport(client.debug), Transport: NewTransport(client.debug),
} }
} }

Loading…
Cancel
Save