mirror of https://github.com/status-im/go-waku.git
fix: criteriaInterest mutex (#1205)
Co-authored-by: Pablo Lopez <p.lopez.lpz@gmail.com>
This commit is contained in:
parent
4c3ec60da5
commit
949684092e
|
@ -37,7 +37,7 @@ type MissingMessageVerifier struct {
|
||||||
messageTracker MessageTracker
|
messageTracker MessageTracker
|
||||||
|
|
||||||
criteriaInterest map[string]criteriaInterest // Track message verification requests and when was the last time a pubsub topic was verified for missing messages
|
criteriaInterest map[string]criteriaInterest // Track message verification requests and when was the last time a pubsub topic was verified for missing messages
|
||||||
criteriaInterestMu sync.Mutex
|
criteriaInterestMu sync.RWMutex
|
||||||
|
|
||||||
C <-chan *protocol.Envelope
|
C <-chan *protocol.Envelope
|
||||||
|
|
||||||
|
@ -110,8 +110,13 @@ func (m *MissingMessageVerifier) Start(ctx context.Context) {
|
||||||
select {
|
select {
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
m.logger.Debug("checking for missing messages...")
|
m.logger.Debug("checking for missing messages...")
|
||||||
m.criteriaInterestMu.Lock()
|
m.criteriaInterestMu.RLock()
|
||||||
for _, interest := range m.criteriaInterest {
|
critIntList := make([]criteriaInterest, 0, len(m.criteriaInterest))
|
||||||
|
for _, value := range m.criteriaInterest {
|
||||||
|
critIntList = append(critIntList, value)
|
||||||
|
}
|
||||||
|
m.criteriaInterestMu.RUnlock()
|
||||||
|
for _, interest := range critIntList {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
@ -123,7 +128,6 @@ func (m *MissingMessageVerifier) Start(ctx context.Context) {
|
||||||
}(interest)
|
}(interest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.criteriaInterestMu.Unlock()
|
|
||||||
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
@ -155,8 +159,8 @@ func (m *MissingMessageVerifier) fetchHistory(c chan<- *protocol.Envelope, inter
|
||||||
}
|
}
|
||||||
|
|
||||||
m.criteriaInterestMu.Lock()
|
m.criteriaInterestMu.Lock()
|
||||||
c := m.criteriaInterest[interest.contentFilter.PubsubTopic]
|
c, ok := m.criteriaInterest[interest.contentFilter.PubsubTopic]
|
||||||
if c.equals(interest) {
|
if ok && c.equals(interest) {
|
||||||
c.lastChecked = now
|
c.lastChecked = now
|
||||||
m.criteriaInterest[interest.contentFilter.PubsubTopic] = c
|
m.criteriaInterest[interest.contentFilter.PubsubTopic] = c
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue