From e675f04bd29a78f6f1f4a316b7607b0f29d229d4 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Fri, 20 Mar 2026 20:27:24 -0300 Subject: [PATCH] maybe this is not necessary? prevent WriteWithError from getting stuck. --- relay.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/relay.go b/relay.go index 9108a0e..c11b27a 100644 --- a/relay.go +++ b/relay.go @@ -434,7 +434,7 @@ func (r *Relay) Write(msg []byte) { // WriteWithError is like Write, but returns an error if the write fails (and the connection gets closed). func (r *Relay) WriteWithError(msg []byte) error { - ch := make(chan error) + ch := make(chan error, 1) if r.writeQueue == nil { return nil @@ -445,7 +445,13 @@ func (r *Relay) WriteWithError(msg []byte) error { return fmt.Errorf("failed to write to %s: %w", r.URL, context.Cause(r.connectionContext)) case r.writeQueue <- writeRequest{msg: msg, answer: ch}: } - return <-ch + + select { + case err := <-ch: + return err + case <-r.connectionContext.Done(): + return fmt.Errorf("failed to write to %s: %w", r.URL, context.Cause(r.connectionContext)) + } } // Publish sends an "EVENT" command to the relay r as in NIP-01 and waits for an OK response.