Skip to content

Commit

Permalink
Merge pull request moby#13430 from runcom/fix-race-modify-request
Browse files Browse the repository at this point in the history
Fix race in httpsRequestModifier.ModifyRequest when writing tlsConfig
  • Loading branch information
LK4D4 committed May 28, 2015
2 parents 37cc42e + a27395e commit 3bda841
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"path/filepath"
"runtime"
"strings"
"sync"
"time"

"github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -56,7 +57,10 @@ func init() {
dockerUserAgent = useragent.AppendVersions("", httpVersion...)
}

type httpsRequestModifier struct{ tlsConfig *tls.Config }
type httpsRequestModifier struct {
mu sync.Mutex
tlsConfig *tls.Config
}

// DRAGONS(tiborvass): If someone wonders why do we set tlsconfig in a roundtrip,
// it's because it's so as to match the current behavior in master: we generate the
Expand Down Expand Up @@ -125,8 +129,10 @@ func (m *httpsRequestModifier) ModifyRequest(req *http.Request) error {
}
}
}
m.mu.Lock()
m.tlsConfig.RootCAs = roots
m.tlsConfig.Certificates = certs
m.mu.Unlock()
}
return nil
}
Expand Down Expand Up @@ -175,7 +181,7 @@ func NewTransport(timeout TimeoutType, secure bool) http.RoundTripper {
if secure {
// note: httpsTransport also handles http transport
// but for HTTPS, it sets up the certs
return transport.NewTransport(tr, &httpsRequestModifier{tlsConfig})
return transport.NewTransport(tr, &httpsRequestModifier{tlsConfig: tlsConfig})
}

return tr
Expand Down

0 comments on commit 3bda841

Please sign in to comment.