diff --git a/internal/nostr/nostr.go b/internal/nostr/nostr.go index 9ca3280..301af7c 100644 --- a/internal/nostr/nostr.go +++ b/internal/nostr/nostr.go @@ -702,12 +702,18 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri waitToReconnectSeconds := 0 for { - // close relays with connection errors before connecting again - // because context expiration has no effect on relays - // TODO: Call relay.Connect on already initialized relays + // context expiration has no effect on relays if relay != nil && relay.Connection != nil && isCustomRelay { relay.Close() } + if ctx.Err() != nil { + svc.Logger.WithFields(logrus.Fields{ + "subscription_id": subscription.ID, + "relay_url": subscription.RelayUrl, + }).Debug("Context canceled, stopping subscription") + svc.stopSubscription(subscription) + return + } time.Sleep(time.Duration(waitToReconnectSeconds) * time.Second) relay, isCustomRelay, err = svc.getRelayConnection(ctx, subscription.RelayUrl) if err != nil {