From 3162837c32e02dec7482da7533738dd521d12e4b Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 9 Apr 2025 15:08:46 +0200 Subject: [PATCH] discovery: listen on ctx in any select For any method that takes a context that has a select that listens on the systems quit channel, we should also listen on the ctx since we should not need to worry about if this context is derived internally or externally. --- discovery/sync_manager.go | 3 +++ discovery/syncer.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/discovery/sync_manager.go b/discovery/sync_manager.go index 99c320d79..807bd99b9 100644 --- a/discovery/sync_manager.go +++ b/discovery/sync_manager.go @@ -538,6 +538,9 @@ func (m *SyncManager) syncerHandler(ctx context.Context) { case <-m.quit: return + + case <-ctx.Done(): + return } } } diff --git a/discovery/syncer.go b/discovery/syncer.go index abbf61923..0b4e7030b 100644 --- a/discovery/syncer.go +++ b/discovery/syncer.go @@ -527,6 +527,9 @@ func (g *GossipSyncer) channelGraphSyncer(ctx context.Context) { case <-g.cg.Done(): return + + case <-ctx.Done(): + return } // We'll enter this state once we've discovered which channels @@ -577,6 +580,9 @@ func (g *GossipSyncer) channelGraphSyncer(ctx context.Context) { case <-g.cg.Done(): return + + case <-ctx.Done(): + return } // This is our final terminal state where we'll only reply to @@ -623,6 +629,9 @@ func (g *GossipSyncer) channelGraphSyncer(ctx context.Context) { case <-g.cg.Done(): return + + case <-ctx.Done(): + return } } } @@ -656,6 +665,9 @@ func (g *GossipSyncer) replyHandler(ctx context.Context) { case <-g.cg.Done(): return + + case <-ctx.Done(): + return } } } @@ -1298,6 +1310,8 @@ func (g *GossipSyncer) ApplyGossipFilter(ctx context.Context, case <-g.syncerSema: case <-g.cg.Done(): return ErrGossipSyncerExiting + case <-ctx.Done(): + return ctx.Err() } // We don't put this in a defer because if the goroutine is launched, @@ -1370,6 +1384,8 @@ func (g *GossipSyncer) FilterGossipMsgs(ctx context.Context, select { case <-g.cg.Done(): return + case <-ctx.Done(): + return default: }