prevent halting in some other places.

This commit is contained in:
fiatjaf 2023-07-11 11:04:48 -03:00
parent f6dddfd770
commit 6e79f72174
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -223,6 +223,9 @@ func (r *Relay) Connect(ctx context.Context) error {
writeRequest.answer <- err
}
close(writeRequest.answer)
case <-r.connectionContext.Done():
// stop here
return
}
}
}()
@ -286,7 +289,10 @@ func (r *Relay) Connect(ctx context.Context) error {
}
// dispatch this to the internal .events channel of the subscription
subscription.events <- &env.Event
select {
case subscription.events <- &env.Event:
case <-subscription.Context.Done():
}
}
case *EOSEEnvelope:
if subscription, ok := r.Subscriptions.Load(string(*env)); ok {
@ -313,7 +319,11 @@ func (r *Relay) Connect(ctx context.Context) error {
// Write queues a message to be sent to the relay.
func (r *Relay) Write(msg []byte) <-chan error {
ch := make(chan error)
r.writeQueue <- writeRequest{msg: msg, answer: ch}
select {
case r.writeQueue <- writeRequest{msg: msg, answer: ch}:
case <-r.connectionContext.Done():
go func() { ch <- fmt.Errorf("connection closed") }()
}
return ch
}