File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff 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 {
728729type httpFallback struct {
729730 super http.RoundTripper
730731 host string
732+ mu sync.Mutex
731733}
732734
733735func (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 {
You can’t perform that action at this time.
0 commit comments