guard against closed channels in subscriptions.

This commit is contained in:
fiatjaf 2023-03-16 15:53:24 -03:00
parent ec34d4eb10
commit c982ad0ab1
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -261,6 +261,11 @@ func (r *Relay) Publish(ctx context.Context, event Event) (Status, error) {
for {
select {
case receivedEvent := <-sub.Events:
if receivedEvent == nil {
// channel is closed
return status, err
}
if receivedEvent.ID == event.ID {
// we got a success, so update our status and proceed to return
mu.Lock()
@ -364,6 +369,10 @@ func (r *Relay) QuerySync(ctx context.Context, filter Filter) []*Event {
for {
select {
case evt := <-sub.Events:
if evt == nil {
// channel is closed
return events
}
events = append(events, evt)
case <-sub.EndOfStoredEvents:
return events