From 81bf320366e49a28e8c7d99323bbbd06a80244cc Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Fri, 2 Aug 2024 15:23:16 +0200 Subject: [PATCH] Set the maximum diff on timeouts Signed-off-by: Piotr Piotrowski --- js.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js.go b/js.go index 5bea1b976..9fec788a7 100644 --- a/js.go +++ b/js.go @@ -2899,7 +2899,11 @@ func (sub *Subscription) Fetch(batch int, opts ...PullOpt) ([]*Msg, error) { } // Make our request expiration a bit shorter than the current timeout. - expires := time.Duration(float64(ttl) * 0.9) + expiresDiff := time.Duration(float64(ttl) * 0.1) + if expiresDiff > 5*time.Second { + expiresDiff = 5 * time.Second + } + expires := ttl - expiresDiff nr.Batch = batch - len(msgs) nr.Expires = expires @@ -3163,7 +3167,11 @@ func (sub *Subscription) FetchBatch(batch int, opts ...PullOpt) (MessageBatch, e ttl = time.Until(deadline) // Make our request expiration a bit shorter than the current timeout. - expires := time.Duration(float64(ttl) * 0.9) + expiresDiff := time.Duration(float64(ttl) * 0.1) + if expiresDiff > 5*time.Second { + expiresDiff = 5 * time.Second + } + expires := ttl - expiresDiff requestBatch := batch - len(result.msgs) req := nextRequest{