fix: check lnclient in event handler (#1987)

* fix: check lnclient in event handler

* fix: stop processing subscriptions events channel if context is done
This commit is contained in:
Roland 2025-12-16 22:42:26 +07:00 committed by GitHub
parent 8c9aeff5b3
commit a5f2c2d692
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View file

@ -47,6 +47,13 @@ func (svc *nip47Service) HandleEvent(ctx context.Context, pool nostrmodels.Simpl
return
}
if lnClient == nil {
logger.Logger.WithFields(logrus.Fields{
"requestEventNostrId": event.ID,
}).Error("cannot handle event due to LNClient not started")
return
}
// store request event
requestEvent := db.RequestEvent{AppId: nil, NostrId: event.ID, State: db.REQUEST_EVENT_STATE_HANDLER_EXECUTING}
err = svc.db.Create(&requestEvent).Error

View file

@ -231,7 +231,12 @@ func (svc *service) watchSubscription(ctx context.Context, pool *nostr.SimplePoo
go func() {
// loop through incoming events
for event := range eventsChannel {
go svc.nip47Service.HandleEvent(ctx, pool, event.Event, svc.lnClient)
select {
case <-ctx.Done():
return
default:
go svc.nip47Service.HandleEvent(ctx, pool, event.Event, svc.lnClient)
}
}
logger.Logger.Debug("Relay subscription events channel ended")
eventsChannelClosed <- struct{}{}