Skip to content

Commit

Permalink
[FIXED] Change Fetch client timeout to a higher value (#1689)
Browse files Browse the repository at this point in the history
* [FIXED] Change Fetch client timeout to a higher value

Signed-off-by: Piotr Piotrowski <piotr@synadia.com>

* Set the maximum diff on timeouts

Signed-off-by: Piotr Piotrowski <piotr@synadia.com>

---------

Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
  • Loading branch information
piotrpio authored Aug 12, 2024
1 parent 3498a06 commit af10233
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions js.go
Original file line number Diff line number Diff line change
Expand Up @@ -2899,10 +2899,11 @@ func (sub *Subscription) Fetch(batch int, opts ...PullOpt) ([]*Msg, error) {
}

// Make our request expiration a bit shorter than the current timeout.
expires := ttl
if ttl >= 20*time.Millisecond {
expires = ttl - 10*time.Millisecond
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
Expand Down Expand Up @@ -3166,10 +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 := ttl
if ttl >= 20*time.Millisecond {
expires = ttl - 10*time.Millisecond
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{
Expand Down
2 changes: 1 addition & 1 deletion test/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ func TestPullSubscribeFetchBatchWithHeartbeat(t *testing.T) {
if msgs.Error() != nil {
t.Fatalf("Unexpected error: %s", msgs.Error())
}
if elapsed < 290*time.Millisecond {
if elapsed < 250*time.Millisecond {
t.Fatalf("Expected timeout after 300ms; got: %v", elapsed)
}

Expand Down

0 comments on commit af10233

Please sign in to comment.