Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: criteriaInterest mutex #1205

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions waku/v2/api/missing/missing_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type MissingMessageVerifier struct {
messageTracker MessageTracker

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

Expand Down Expand Up @@ -110,8 +110,10 @@ func (m *MissingMessageVerifier) Start(ctx context.Context) {
select {
case <-t.C:
m.logger.Debug("checking for missing messages...")
m.criteriaInterestMu.Lock()
for _, interest := range m.criteriaInterest {
m.criteriaInterestMu.RLock()
critIntList := m.criteriaInterest
richard-ramos marked this conversation as resolved.
Show resolved Hide resolved
m.criteriaInterestMu.RUnlock()
for _, interest := range critIntList {
select {
case <-ctx.Done():
return
Expand All @@ -123,7 +125,6 @@ func (m *MissingMessageVerifier) Start(ctx context.Context) {
}(interest)
}
}
m.criteriaInterestMu.Unlock()

case <-ctx.Done():
return
Expand Down Expand Up @@ -155,8 +156,8 @@ func (m *MissingMessageVerifier) fetchHistory(c chan<- *protocol.Envelope, inter
}

m.criteriaInterestMu.Lock()
c := m.criteriaInterest[interest.contentFilter.PubsubTopic]
if c.equals(interest) {
c, ok := m.criteriaInterest[interest.contentFilter.PubsubTopic]
if ok && c.equals(interest) {
c.lastChecked = now
m.criteriaInterest[interest.contentFilter.PubsubTopic] = c
}
Expand Down
Loading