Add RW lock when iterating mQueue

This commit is contained in:
yo 2022-11-18 13:59:39 +01:00
parent 503fec99a8
commit e484d80314

View File

@ -354,7 +354,8 @@ func cleanMQueue(mqueue map[string]*OpenLdapConnection, mqMtx *sync.Mutex, age t
log.Printf("Start cleaning queue task: %d items in queue", len(mqueue))
// Do we need read lock?
// We need lock here
mqMtx.Lock()
for uid, ldcon := range mqueue {
ok = false
// Check if a close operation exist
@ -366,11 +367,11 @@ func cleanMQueue(mqueue map[string]*OpenLdapConnection, mqMtx *sync.Mutex, age t
}
}
if ok == true {
mqMtx.Lock()
// We already in RW lock
delete(mqueue, uid)
mqMtx.Unlock()
}
}
mqMtx.Unlock()
log.Printf("Finished cleaning queue task: %d items in queue", len(mqueue))
}