avoid sending to closed Events/UniqueEvents channels.

This commit is contained in:
fiatjaf
2022-02-07 11:33:45 -03:00
parent 7760f53ce2
commit ef1f548212
2 changed files with 11 additions and 4 deletions

View File

@@ -152,6 +152,7 @@ func (r *RelayPool) Add(url string, policy RelayPoolPolicy) error {
continue
}
if !subscription.stopped {
subscription.Events <- EventMessage{
Relay: nm,
Event: event,
@@ -159,6 +160,7 @@ func (r *RelayPool) Add(url string, policy RelayPoolPolicy) error {
}
}
}
}
}()
return nil

View File

@@ -9,6 +9,8 @@ type Subscription struct {
started bool
UniqueEvents chan Event
stopped bool
}
type EventMessage struct {
@@ -24,6 +26,7 @@ func (subscription Subscription) Unsub() {
})
}
subscription.stopped = true
if subscription.Events != nil {
close(subscription.Events)
}
@@ -57,9 +60,11 @@ func (subscription Subscription) startHandlingUnique() {
continue
}
seen[em.Event.ID] = struct{}{}
if !subscription.stopped {
subscription.UniqueEvents <- em.Event
}
}
}
func (subscription Subscription) removeRelay(relay string) {
if conn, ok := subscription.relays[relay]; ok {