mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-29 11:12:04 +01:00
guard against closed channels in subscriptions.
This commit is contained in:
parent
ec34d4eb10
commit
c982ad0ab1
9
relay.go
9
relay.go
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user