From ad0f73fa9cf8f7ce720257c5b438d5b8c0c0c817 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 30 May 2023 13:47:47 -0300 Subject: [PATCH] ensure subscription dies if the relay connection dies. --- relay.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/relay.go b/relay.go index 39f8e17..59d2cf2 100644 --- a/relay.go +++ b/relay.go @@ -402,6 +402,12 @@ func (r *Relay) PrepareSubscription(ctx context.Context) *Subscription { ctx, cancel := context.WithCancel(ctx) + go func() { + // ensure the subscription dies if the relay connection dies + <-r.connectionContext.Done() + cancel() + }() + return &Subscription{ Relay: r, Context: ctx,