fix: stop creating goroutines if context is already canceled (#1213)

This commit is contained in:
richΛrd 2024-08-30 11:46:19 -04:00 committed by GitHub
parent 69e1b559bc
commit 27d640e391
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 0 deletions

View File

@ -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 {
@ -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()