Skip to content

Commit

Permalink
fix: listen to relay context done message
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Jan 5, 2024
1 parent dc6a62c commit dd59887
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 10 additions & 9 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit dd59887

Please sign in to comment.