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 (
28
28
"os"
29
29
"path"
30
30
"strings"
31
+ "sync"
31
32
32
33
"github.com/containerd/errdefs"
33
34
"github.com/containerd/log"
@@ -728,11 +729,16 @@ func NewHTTPFallback(transport http.RoundTripper) http.RoundTripper {
728
729
type httpFallback struct {
729
730
super http.RoundTripper
730
731
host string
732
+ mu sync.Mutex
731
733
}
732
734
733
735
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
+
734
740
// only fall back if the same host had previously fell back
735
- if f . host != r . URL . Host {
741
+ if ! fallback {
736
742
resp , err := f .super .RoundTrip (r )
737
743
if ! isTLSError (err ) && ! isPortError (err , r .URL .Host ) {
738
744
return resp , err
@@ -745,8 +751,12 @@ func (f *httpFallback) RoundTrip(r *http.Request) (*http.Response, error) {
745
751
plainHTTPRequest := * r
746
752
plainHTTPRequest .URL = & plainHTTPUrl
747
753
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 ()
750
760
751
761
// update body on the second attempt
752
762
if r .Body != nil && r .GetBody != nil {
You can’t perform that action at this time.
0 commit comments