Fix race condition in database package. Simplify db locking

This commit is contained in:
Patrick Pacher 2020-09-21 15:18:54 +02:00
parent 93a0b27ea2
commit 50a10485e1
No known key found for this signature in database
GPG key ID: E8CD2DA160925A6D
3 changed files with 34 additions and 46 deletions

View file

@ -35,10 +35,8 @@ func RegisterHook(q *query.Query, hook Hook) (*RegisteredHook, error) {
return nil, err
}
c.readLock.Lock()
defer c.readLock.Unlock()
c.writeLock.Lock()
defer c.writeLock.Unlock()
c.exclusiveAccess.Lock()
defer c.exclusiveAccess.Unlock()
rh := &RegisteredHook{
q: q,
@ -55,10 +53,8 @@ func (h *RegisteredHook) Cancel() error {
return err
}
c.readLock.Lock()
defer c.readLock.Unlock()
c.writeLock.Lock()
defer c.writeLock.Unlock()
c.exclusiveAccess.Lock()
defer c.exclusiveAccess.Unlock()
for key, hook := range c.hooks {
if hook.q == h.q {