Skip to content

Commit 0975ec0

Browse files
authored
Merge pull request containerd#10342 from dmcgowan/add-mutex-fallback-host
Adds a mutex to protect fallback host
2 parents ab61734 + 38e2f00 commit 0975ec0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

core/remotes/docker/resolver.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"os"
2929
"path"
3030
"strings"
31+
"sync"
3132

3233
"github.com/containerd/errdefs"
3334
"github.com/containerd/log"
@@ -728,11 +729,16 @@ func NewHTTPFallback(transport http.RoundTripper) http.RoundTripper {
728729
type httpFallback struct {
729730
super http.RoundTripper
730731
host string
732+
mu sync.Mutex
731733
}
732734

733735
func (f *httpFallback) RoundTrip(r *http.Request) (*http.Response, error) {
736+
f.mu.Lock()
737+
fallback := f.host == r.URL.Host
738+
f.mu.Unlock()
739+
734740
// only fall back if the same host had previously fell back
735-
if f.host != r.URL.Host {
741+
if !fallback {
736742
resp, err := f.super.RoundTrip(r)
737743
if !isTLSError(err) && !isPortError(err, r.URL.Host) {
738744
return resp, err
@@ -745,8 +751,12 @@ func (f *httpFallback) RoundTrip(r *http.Request) (*http.Response, error) {
745751
plainHTTPRequest := *r
746752
plainHTTPRequest.URL = &plainHTTPUrl
747753

748-
if f.host != r.URL.Host {
749-
f.host = r.URL.Host
754+
if !fallback {
755+
f.mu.Lock()
756+
if f.host != r.URL.Host {
757+
f.host = r.URL.Host
758+
}
759+
f.mu.Unlock()
750760

751761
// update body on the second attempt
752762
if r.Body != nil && r.GetBody != nil {

0 commit comments

Comments
 (0)