Proper timeout handling in func (*pullConsumer) fetch()
#1482
Labels
proposal
Enhancement idea or proposal
func (*pullConsumer) fetch()
#1482
Proposed change
IMHO, there're something we can improve in these lines of code.
nats.go/jetstream/pull.go
Lines 770 to 772 in 8712190
time.Timer
according to the doc. Before the timeout reached, the timer is not GC-able. For client with Higher throughput and with higherExpires
, there will be more concurrent timer running, which is unnecessary.time.Timer.Stop()
andtime.Timer.Reset()
to reuse thetime.Timer
. In this way, the loop will be more efficient.Expires
and a constant1 * time.Second
, which is the same field as the request pass to server. For client or server under stress, the timeout may easily reached. Especially forFetchNoWait()
.Expires
into 2 options, one used as request that passes to the server, another serves as client receiving timeout.context.Context.Done()
for receiving timeout.UNSUB
should be unacked explicitly (instread of waiting server ack timeout). Current implementation is just dropping the messages. For those usingAckPolicy: AckAll
, this behavior is dangerous, we could lose message permanently if we received later message and ack them. It's possible because we normally write a loop to batch request (Fetch()
).Use case
Contribution
Yes
The text was updated successfully, but these errors were encountered: