Skip to content

Commit

Permalink
Fix TLS configuration data race (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcharum authored Mar 21, 2020
1 parent 02b2e67 commit 9299430
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ec2system/ec2machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,16 @@ func (s *System) HTTPClient() *http.Client {
// TODO(marius): propagate error to caller
err := s.clientOnce.Do(func() (err error) {
s.clientConfig, _, err = s.authority.HTTPSConfig()
if err != nil {
return
}
// Set up the TLS configuration for http/2. If we didn't do this,
// http.ConfigureTransport would. However, because we share the
// configuration between Transports and HTTPClient can be called
// concurrently, we do it ourselves to avoid a data race. See:
// https://github.com/golang/net/blob/244492dfa37a/http2/transport.go#L154-L159
s.clientConfig.NextProtos = append([]string{"h2"}, s.clientConfig.NextProtos...)
s.clientConfig.NextProtos = append(s.clientConfig.NextProtos, "http/1.1")
return
})
if err != nil {
Expand Down

0 comments on commit 9299430

Please sign in to comment.