Protect report entries map with mutex to prevent concurrent writes causing a bad map state

This commit is contained in:
Roland Shoemaker 2015-09-02 17:45:19 -07:00
parent d5599c47c3
commit 961231ba48
1 changed files with 6 additions and 1 deletions

View File

@ -70,8 +70,9 @@ type certChecker struct {
pa core.PolicyAuthority
dbMap *gorp.DbMap
certs chan core.Certificate
issuedReport report
clock clock.Clock
rMu *sync.Mutex
issuedReport report
}
func newChecker(saDbMap *gorp.DbMap, paDbMap *gorp.DbMap, enforceWhitelist bool) certChecker {
@ -82,8 +83,10 @@ func newChecker(saDbMap *gorp.DbMap, paDbMap *gorp.DbMap, enforceWhitelist bool)
dbMap: saDbMap,
certs: make(chan core.Certificate, batchSize),
clock: clock.Default(),
rMu: new(sync.Mutex),
}
c.issuedReport.Entries = make(map[string]reportEntry)
return c
}
@ -130,10 +133,12 @@ func (c *certChecker) processCerts(wg *sync.WaitGroup) {
for cert := range c.certs {
problems := c.checkCert(cert)
valid := len(problems) == 0
c.rMu.Lock()
c.issuedReport.Entries[cert.Serial] = reportEntry{
Valid: valid,
Problems: problems,
}
c.rMu.Unlock()
if !valid {
atomic.AddInt64(&c.issuedReport.BadCerts, 1)
} else {