diff --git a/.env.example b/.env.example index e0e7c094..5aa2ed4f 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,7 @@ DATABASE_URI=file:nwc.db NOSTR_PRIVKEY= COOKIE_SECRET=secretsecret RELAY=wss://relay.getalby.com/v1 +#RELAY=ws://localhost:7447/v1 PUBLIC_RELAY= PORT=8080 diff --git a/service.go b/service.go index 5efa4b1f..8707bdf4 100644 --- a/service.go +++ b/service.go @@ -128,17 +128,18 @@ func (svc *Service) StartSubscription(ctx context.Context, sub *nostr.Subscripti } }() - <-ctx.Done() - if sub.Relay.ConnectionError != nil { - svc.Logger.Errorf("Relay error %v", ctx.Err()) + select { + case <-sub.Relay.Context().Done(): + svc.Logger.Errorf("Relay error %v", sub.Relay.ConnectionError) return sub.Relay.ConnectionError + case <-ctx.Done(): + if ctx.Err() != context.Canceled { + svc.Logger.Errorf("Subscription error %v", ctx.Err()) + return ctx.Err() + } + svc.Logger.Info("Exiting subscription.") + return nil } - if ctx.Err() != context.Canceled { - svc.Logger.Errorf("Subscription error %v", ctx.Err()) - return ctx.Err() - } - svc.Logger.Info("Exiting subscription.") - return nil } func (svc *Service) HandleEvent(ctx context.Context, event *nostr.Event) (result *nostr.Event, err error) {