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.
This commit is contained in:
sputn1ck 2024-10-15 19:28:21 +02:00
parent 2c32575c75
commit d6c7237b77
No known key found for this signature in database
GPG key ID: 671103D881A5F0E4

View file

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