Skip to content

Commit af10233

Browse files
authoredAug 12, 2024··
[FIXED] Change Fetch client timeout to a higher value (#1689)
* [FIXED] Change Fetch client timeout to a higher value Signed-off-by: Piotr Piotrowski <[email protected]> * Set the maximum diff on timeouts Signed-off-by: Piotr Piotrowski <[email protected]> --------- Signed-off-by: Piotr Piotrowski <[email protected]>
1 parent 3498a06 commit af10233

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed
 

‎js.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -2899,10 +2899,11 @@ func (sub *Subscription) Fetch(batch int, opts ...PullOpt) ([]*Msg, error) {
28992899
}
29002900

29012901
// Make our request expiration a bit shorter than the current timeout.
2902-
expires := ttl
2903-
if ttl >= 20*time.Millisecond {
2904-
expires = ttl - 10*time.Millisecond
2902+
expiresDiff := time.Duration(float64(ttl) * 0.1)
2903+
if expiresDiff > 5*time.Second {
2904+
expiresDiff = 5 * time.Second
29052905
}
2906+
expires := ttl - expiresDiff
29062907

29072908
nr.Batch = batch - len(msgs)
29082909
nr.Expires = expires
@@ -3166,10 +3167,11 @@ func (sub *Subscription) FetchBatch(batch int, opts ...PullOpt) (MessageBatch, e
31663167
ttl = time.Until(deadline)
31673168

31683169
// Make our request expiration a bit shorter than the current timeout.
3169-
expires := ttl
3170-
if ttl >= 20*time.Millisecond {
3171-
expires = ttl - 10*time.Millisecond
3170+
expiresDiff := time.Duration(float64(ttl) * 0.1)
3171+
if expiresDiff > 5*time.Second {
3172+
expiresDiff = 5 * time.Second
31723173
}
3174+
expires := ttl - expiresDiff
31733175

31743176
requestBatch := batch - len(result.msgs)
31753177
req := nextRequest{

‎test/js_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ func TestPullSubscribeFetchBatchWithHeartbeat(t *testing.T) {
13571357
if msgs.Error() != nil {
13581358
t.Fatalf("Unexpected error: %s", msgs.Error())
13591359
}
1360-
if elapsed < 290*time.Millisecond {
1360+
if elapsed < 250*time.Millisecond {
13611361
t.Fatalf("Expected timeout after 300ms; got: %v", elapsed)
13621362
}
13631363

0 commit comments

Comments
 (0)
Please sign in to comment.