Skip to content

Commit 9f971cd

Browse files
committed
staticaddr: fix crash in loop-in manager shutdown
If the notification manager shuts down, sweepReqs channel is closed and sweepReq object received from it becomes nil, causing panic in handleLoopInSweepReq. Now this is fixed by checking if the channel was closed and if it was shutting down loop-in manager itself.
1 parent 890b91c commit 9f971cd

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

staticaddr/loopin/manager.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,25 @@ func (m *Manager) Run(ctx context.Context) error {
205205
case request.respChan <- resp:
206206

207207
case <-ctx.Done():
208-
// Noify subroutines that the main loop has been
209-
// canceled.
208+
// Notify subroutines that the main loop has
209+
// been canceled.
210210
close(m.exitChan)
211211

212212
return ctx.Err()
213213
}
214214

215-
case sweepReq := <-sweepReqs:
215+
case sweepReq, ok := <-sweepReqs:
216+
if !ok {
217+
// The channel has been closed, we'll stop the
218+
// loop-in manager.
219+
log.Debugf("Stopping loop-in manager " +
220+
"(ntfnChan closed)")
221+
222+
close(m.exitChan)
223+
224+
return fmt.Errorf("ntfnChan closed")
225+
}
226+
216227
err = m.handleLoopInSweepReq(ctx, sweepReq)
217228
if err != nil {
218229
log.Errorf("Error handling loop-in sweep "+

0 commit comments

Comments
 (0)