maybe this is not necessary? prevent WriteWithError from getting stuck.

This commit is contained in:
fiatjaf
2026-03-20 20:27:24 -03:00
parent 0630bbe4e9
commit e675f04bd2
+8 -2
View File
@@ -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.