Skip to content

Commit

Permalink
[FAB-11135] tls certpool lock fix
Browse files Browse the repository at this point in the history
Change-Id: I7754d3c9eb8bcc6cd5b0288f3e7d6c4278028c6b
Signed-off-by: Sudesh Shetty <[email protected]>
  • Loading branch information
sudeshrshetty committed Aug 8, 2018
1 parent 0424521 commit 972a009
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/core/config/comm/tls/certpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type certPool struct {
certPool *x509.CertPool
certs []*x509.Certificate
certsByName map[string][]int
lock sync.Mutex
lock sync.RWMutex
dirty int32
certQueue []*x509.Certificate
}
Expand All @@ -52,17 +52,20 @@ func (c *certPool) Get() (*x509.CertPool, error) {

//if dirty then add certs from queue to cert pool
if atomic.CompareAndSwapInt32(&c.dirty, 1, 0) {

c.lock.Lock()
defer c.lock.Unlock()

//add all new certs in queue to cert pool
for _, cert := range c.certQueue {
c.certPool.AddCert(cert)
}
c.certQueue = []*x509.Certificate{}

c.lock.Unlock()
}

c.lock.RLock()
defer c.lock.RUnlock()

return c.certPool, nil
}

Expand Down

0 comments on commit 972a009

Please sign in to comment.