Skip to content

Commit

Permalink
fix: stop creating goroutines if context is already canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Aug 30, 2024
1 parent 69e1b55 commit 0a936b0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions waku/v2/api/missing/missing_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ func (m *MissingMessageVerifier) fetchHistory(c chan<- *protocol.Envelope, inter
j = len(contentTopics)
}

select {
case <-interest.ctx.Done():
return
default:
// continue...
}

now := m.timesource.Now()
err := m.fetchMessagesBatch(c, interest, i, j, now)
if err != nil {
Expand Down Expand Up @@ -260,6 +267,13 @@ func (m *MissingMessageVerifier) fetchMessagesBatch(c chan<- *protocol.Envelope,
j = len(missingHashes)
}

select {
case <-interest.ctx.Done():
return nil
default:
// continue...
}

wg.Add(1)
go func(messageHashes []pb.MessageHash) {
defer wg.Wait()
Expand Down

0 comments on commit 0a936b0

Please sign in to comment.