From d6c7237b772437bae6b04237b671ffd619c997f1 Mon Sep 17 00:00:00 2001 From: sputn1ck Date: Tue, 15 Oct 2024 19:28:21 +0200 Subject: [PATCH] reservations: check if channel is closing This commit adds a check to the runtime loop of the reservation manager to check if the channel is closing before trying to read from it. --- instantout/reservation/manager.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/instantout/reservation/manager.go b/instantout/reservation/manager.go index faffbc594..3a20d113d 100644 --- a/instantout/reservation/manager.go +++ b/instantout/reservation/manager.go @@ -56,7 +56,7 @@ func (m *Manager) Run(ctx context.Context, height int32) error { return err } - ntfnChan := m.cfg.NotificationManager.SubscribeReservations(ctx) + ntfnChan := m.cfg.NotificationManager.SubscribeReservations(runCtx) for { select { @@ -64,7 +64,14 @@ func (m *Manager) Run(ctx context.Context, height int32) error { log.Debugf("Received block %v", height) currentHeight = height - case reservationRes := <-ntfnChan: + case reservationRes, ok := <-ntfnChan: + if !ok { + // The channel has been closed, we'll stop the + // reservation manager. + log.Debugf("Stopping reservation manager (ntfnChan closed)") + return nil + } + log.Debugf("Received reservation %x", reservationRes.ReservationId) _, err := m.newReservation(