Skip to content

Commit 080751a

Browse files
authored
Give the ping context a timeout. (#1163)
Debugging why requests to an insecure registry seem to hang, I noticed that there are 3+ requests to the https endpoint before it falls back to http (at that point my logs truncate because the test was over). The time between the request being issued and completing in the roundtripper was ~30s each. This change gives each ping a generous 5s timeout to complete each request.
1 parent dd49079 commit 080751a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

pkg/v1/remote/transport/ping.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io/ioutil"
2323
"net/http"
2424
"strings"
25+
"time"
2526

2627
authchallenge "github.com/docker/distribution/registry/client/auth/challenge"
2728
"github.com/google/go-containerregistry/pkg/name"
@@ -86,7 +87,12 @@ func ping(ctx context.Context, reg name.Registry, t http.RoundTripper) (*pingRes
8687
if err != nil {
8788
return nil, err
8889
}
89-
resp, err := client.Do(req.WithContext(ctx))
90+
// The ping handler should be extremely fast, but for registries that serve
91+
// over http, it could take a while to fallback from https (esp. if the
92+
// transport has retries). So give each ping attempt a (generous) 5s timeout.
93+
pctx, cancel := context.WithTimeout(ctx, 5*time.Second)
94+
defer cancel()
95+
resp, err := client.Do(req.WithContext(pctx))
9096
if err != nil {
9197
errs = append(errs, err.Error())
9298
// Potentially retry with http.

0 commit comments

Comments
 (0)