From 2314db57a105fe079971edcaf9642315f352f860 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 11 Apr 2023 15:33:29 -0300 Subject: [PATCH] tweak timeouts on Publish() --- relay.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/relay.go b/relay.go index c3f15fc..6d7d08d 100644 --- a/relay.go +++ b/relay.go @@ -273,9 +273,9 @@ func (r *Relay) Publish(ctx context.Context, event Event) (Status, error) { var mu sync.Mutex if _, ok := ctx.Deadline(); !ok { - // if no timeout is set, force it to 4 seconds + // if no timeout is set, force it to 7 seconds var cancel context.CancelFunc - ctx, cancel = context.WithTimeout(ctx, 4*time.Second) + ctx, cancel = context.WithTimeout(ctx, 7*time.Second) defer cancel() } @@ -322,12 +322,11 @@ func (r *Relay) Publish(ctx context.Context, event Event) (Status, error) { case <-r.ConnectionContext.Done(): // same as above, but when the relay loses connectivity entirely return status, err - case <-time.After(2 * time.Second): - // if we don't get an OK after 2 seconds, try to subscribe to the event + case <-time.After(4 * time.Second): + // if we don't get an OK after 4 seconds, try to subscribe to the event if err := sub.Fire(); err != nil { InfoLogger.Printf("failed to subscribe to just published event %s at %s: %s", event.ID, r.URL, err) } - case receivedEvent := <-sub.Events: if receivedEvent == nil { // channel is closed