mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
Fix locking in runtime and hashmap storage
This commit is contained in:
parent
75ab99d681
commit
19f75bb6ca
2 changed files with 14 additions and 22 deletions
|
@ -104,17 +104,16 @@ func (hm *HashMap) queryExecutor(queryIter *iterator.Iterator, q *query.Query, l
|
|||
|
||||
mapLoop:
|
||||
for key, record := range hm.db {
|
||||
record.Lock()
|
||||
if !q.MatchesKey(key) ||
|
||||
!q.MatchesRecord(record) ||
|
||||
!record.Meta().CheckValidity() ||
|
||||
!record.Meta().CheckPermission(local, internal) {
|
||||
|
||||
switch {
|
||||
case !q.MatchesKey(key):
|
||||
continue
|
||||
case !q.MatchesRecord(record):
|
||||
continue
|
||||
case !record.Meta().CheckValidity():
|
||||
continue
|
||||
case !record.Meta().CheckPermission(local, internal):
|
||||
record.Unlock()
|
||||
continue
|
||||
}
|
||||
record.Unlock()
|
||||
|
||||
select {
|
||||
case <-queryIter.Done:
|
||||
|
|
|
@ -202,23 +202,16 @@ func (r *Registry) Query(q *query.Query, local, internal bool) (*iterator.Iterat
|
|||
}
|
||||
|
||||
for _, r := range records {
|
||||
// TODO(ppacher): do we need to lock r?
|
||||
// storage/hashmap does not lock the records
|
||||
// before sending them to the iterator but
|
||||
// better make sure that's correct.
|
||||
r.Lock()
|
||||
if q.MatchesKey(r.DatabaseKey()) ||
|
||||
!r.Meta().CheckValidity() ||
|
||||
!r.Meta().CheckPermission(local, internal) ||
|
||||
!q.MatchesRecord(r) {
|
||||
|
||||
if !strings.HasPrefix(r.DatabaseKey(), searchPrefix) {
|
||||
continue
|
||||
}
|
||||
if !r.Meta().CheckValidity() {
|
||||
continue
|
||||
}
|
||||
if !r.Meta().CheckPermission(local, internal) {
|
||||
continue
|
||||
}
|
||||
if !q.MatchesRecord(r) {
|
||||
r.Unlock()
|
||||
continue
|
||||
}
|
||||
r.Unlock()
|
||||
|
||||
select {
|
||||
case iter.Next <- r:
|
||||
|
|
Loading…
Add table
Reference in a new issue