Skip to content

Commit

Permalink
Give the ping context a timeout. (#1163)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mattmoor authored Nov 4, 2021
1 parent dd49079 commit 080751a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/v1/remote/transport/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io/ioutil"
"net/http"
"strings"
"time"

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

0 comments on commit 080751a

Please sign in to comment.