protect against faulty relays that send more than one EOSE halting us

using sync.Once{} to only emit to the EndOfStoredEvents channel once
(it has capacity 1 so anything over that would halt).
This commit is contained in:
fiatjaf 2022-11-16 10:07:15 -03:00
parent 7538f1108d
commit 69ccfbaa08
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 7 additions and 2 deletions

View File

@ -140,7 +140,9 @@ func (r *Relay) Connect() error {
var channel string
json.Unmarshal(jsonMessage[1], &channel)
if subscription, ok := r.subscriptions.Load(channel); ok {
subscription.EndOfStoredEvents <- struct{}{}
subscription.emitEose.Do(func() {
subscription.EndOfStoredEvents <- struct{}{}
})
}
case "OK":
if len(jsonMessage) < 3 {

View File

@ -1,5 +1,7 @@
package nostr
import "sync"
type Subscription struct {
id string
conn *Connection
@ -8,7 +10,8 @@ type Subscription struct {
Events chan Event
EndOfStoredEvents chan struct{}
stopped bool
stopped bool
emitEose sync.Once
}
type EventMessage struct {