Skip to content

Commit

Permalink
fix: check relay.connection before closing
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Aug 27, 2024
1 parent d2f55fd commit d529dcc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/nostr/nostr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit d529dcc

Please sign in to comment.