Skip to content

Commit 4c7a595

Browse files
author
OpenShift Bot
committed
Merge pull request #8574 from smarterclayton/retry_import
Merged by openshift-bot
2 parents 8fb838f + 8faa82f commit 4c7a595

File tree

5 files changed

+755
-351
lines changed

5 files changed

+755
-351
lines changed

Diff for: pkg/dockerregistry/client.go

+17
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ type v2repository struct {
455455
name string
456456
endpoint url.URL
457457
token string
458+
retries int
458459
}
459460

460461
// v2tags describes the tags/list returned by the Docker V2 registry.
@@ -482,6 +483,13 @@ func (repo *v2repository) getTags(c *connection) (map[string]string, error) {
482483
switch code := resp.StatusCode; {
483484
case code == http.StatusUnauthorized:
484485
if len(repo.token) != 0 {
486+
// The DockerHub returns JWT tokens that take effect at "now" at second resolution, which means clients can
487+
// be rejected when requests are made near the time boundary.
488+
if repo.retries > 0 {
489+
repo.retries--
490+
time.Sleep(time.Second / 2)
491+
return repo.getTags(c)
492+
}
485493
delete(c.cached, repo.name)
486494
// docker will not return a NotFound on any repository URL - for backwards compatibilty, return NotFound on the
487495
// repo
@@ -491,6 +499,7 @@ func (repo *v2repository) getTags(c *connection) (map[string]string, error) {
491499
if err != nil {
492500
return nil, fmt.Errorf("error getting image tags for %s: %v", repo.name, err)
493501
}
502+
repo.retries = 2
494503
repo.token = token
495504
return repo.getTags(c)
496505

@@ -532,6 +541,13 @@ func (repo *v2repository) getTaggedImage(c *connection, tag, userTag string) (*I
532541
switch code := resp.StatusCode; {
533542
case code == http.StatusUnauthorized:
534543
if len(repo.token) != 0 {
544+
// The DockerHub returns JWT tokens that take effect at "now" at second resolution, which means clients can
545+
// be rejected when requests are made near the time boundary.
546+
if repo.retries > 0 {
547+
repo.retries--
548+
time.Sleep(time.Second / 2)
549+
return repo.getTaggedImage(c, tag, userTag)
550+
}
535551
delete(c.cached, repo.name)
536552
// docker will not return a NotFound on any repository URL - for backwards compatibilty, return NotFound on the
537553
// repo
@@ -543,6 +559,7 @@ func (repo *v2repository) getTaggedImage(c *connection, tag, userTag string) (*I
543559
if err != nil {
544560
return nil, fmt.Errorf("error getting image for %s:%s: %v", repo.name, tag, err)
545561
}
562+
repo.retries = 2
546563
repo.token = token
547564
return repo.getTaggedImage(c, tag, userTag)
548565
case code == http.StatusNotFound:

0 commit comments

Comments
 (0)