mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
Not send sentry task to closed tasks channel (#4467)
* Not send sentry task to closed tasks channel * Add comments Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
This commit is contained in:
parent
bca563fd0f
commit
df3eea6414
@ -83,6 +83,8 @@ func (pi *PeerInfo) Close() {
|
||||
defer pi.lock.Unlock()
|
||||
if pi.tasks != nil {
|
||||
close(pi.tasks)
|
||||
// Setting this to nil because other functions detect the closure of the channel by checking pi.tasks == nil
|
||||
pi.tasks = nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,11 +146,16 @@ func (pi *PeerInfo) Remove() {
|
||||
func (pi *PeerInfo) Async(f func()) {
|
||||
pi.lock.Lock()
|
||||
defer pi.lock.Unlock()
|
||||
if pi.tasks == nil {
|
||||
// Too late, the task channel has been closed
|
||||
return
|
||||
}
|
||||
select {
|
||||
case <-pi.removed: // noop if peer removed
|
||||
case <-pi.ctx.Done():
|
||||
if pi.tasks != nil {
|
||||
close(pi.tasks)
|
||||
// Setting this to nil because other functions detect the closure of the channel by checking pi.tasks == nil
|
||||
pi.tasks = nil
|
||||
}
|
||||
case pi.tasks <- f:
|
||||
|
Loading…
Reference in New Issue
Block a user