Skip to content

Commit

Permalink
fix(http-client): avoid a data race EE-5634
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-portainer committed Jun 23, 2023
1 parent d083787 commit dbd7adc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions edge/client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/x509"
"net/http"
"os"
"sync"
"time"

"github.com/rs/zerolog/log"
Expand All @@ -22,6 +23,7 @@ type edgeHTTPClient struct {
certMTime time.Time
keyMTime time.Time
caMTime time.Time
mu sync.RWMutex
}

func BuildHTTPClient(timeout float64, options *agent.Options) *edgeHTTPClient {
Expand All @@ -35,17 +37,25 @@ func BuildHTTPClient(timeout float64, options *agent.Options) *edgeHTTPClient {
revokeService: revokeService,
}

c.mu.Lock()
c.httpClient.Transport = c.buildTransport()
c.mu.Unlock()

return c
}

func (c *edgeHTTPClient) Do(req *http.Request) (*http.Response, error) {
if c.certsNeedsRotation() {
log.Debug().Msg("reloading certificates")

c.mu.Lock()
c.httpClient.Transport = c.buildTransport()
c.mu.Unlock()
}

c.mu.RLock()
defer c.mu.RUnlock()

return c.httpClient.Do(req)
}

Expand Down

0 comments on commit dbd7adc

Please sign in to comment.