From d529dcc8cea0e7c97b62ef94d196df90dd5bd60a Mon Sep 17 00:00:00 2001 From: im-adithya Date: Tue, 27 Aug 2024 15:55:47 +0530 Subject: [PATCH] fix: check relay.connection before closing --- internal/nostr/nostr.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/nostr/nostr.go b/internal/nostr/nostr.go index 2f61bd8..9ca3280 100644 --- a/internal/nostr/nostr.go +++ b/internal/nostr/nostr.go @@ -705,31 +705,31 @@ func (svc *Service) startSubscription(ctx context.Context, subscription *Subscri // close relays with connection errors before connecting again // because context expiration has no effect on relays // TODO: Call relay.Connect on already initialized relays - if relay != nil && isCustomRelay { + if relay != nil && relay.Connection != nil && isCustomRelay { relay.Close() } time.Sleep(time.Duration(waitToReconnectSeconds) * time.Second) relay, isCustomRelay, err = svc.getRelayConnection(ctx, subscription.RelayUrl) if err != nil { // TODO: notify user about relay failure + waitToReconnectSeconds = max(waitToReconnectSeconds, 1) + waitToReconnectSeconds = min(waitToReconnectSeconds * 2, 900) svc.Logger.WithError(err).WithFields(logrus.Fields{ "subscription_id": subscription.ID, "relay_url": subscription.RelayUrl, - }).Errorf("Failed to connect to relay, retrying in %vs...", waitToReconnectSeconds) - waitToReconnectSeconds = max(waitToReconnectSeconds, 1) - waitToReconnectSeconds = min(waitToReconnectSeconds * 2, 900) + }).Errorf("Failed to connect to relay, retrying in %vs...", waitToReconnectSeconds) continue } sub, err := relay.Subscribe(ctx, []nostr.Filter{*filter}) if err != nil { // TODO: notify user about subscription failure + waitToReconnectSeconds = max(waitToReconnectSeconds, 1) + waitToReconnectSeconds = min(waitToReconnectSeconds * 2, 900) svc.Logger.WithError(err).WithFields(logrus.Fields{ "subscription_id": subscription.ID, "relay_url": subscription.RelayUrl, }).Errorf("Failed to subscribe to relay, retrying in %vs...", waitToReconnectSeconds) - waitToReconnectSeconds = max(waitToReconnectSeconds, 1) - waitToReconnectSeconds = min(waitToReconnectSeconds * 2, 900) continue }