Chia-Ping Tsai created KAFKA-21554:
--------------------------------------
Summary: ConsoleConsumer doesn't honor timeout-ms
Key: KAFKA-21554
URL: https://issues.apache.org/jira/browse/KAFKA-21554
Project: Kafka
Issue Type: Bug
Reporter: Chia-Ping Tsai
Assignee: Chia-Ping Tsai
{code:java}
ConsumerRecord<byte[], byte[]> receive() {
long startTimeMs = time.milliseconds();
while (!recordIter.hasNext()) {
recordIter =
consumer.poll(Duration.ofMillis(timeoutMs)).iterator();
if (!recordIter.hasNext() && (time.milliseconds() - startTimeMs
> timeoutMs)) {
throw new TimeoutException();
}
}
return recordIter.next();
}
{code}
The above code always picks up the full {{timeoutMs}} in each poll, so it is
easy to exceed the expected timeout. We should use the remaining timeout
instead.
{code:java}
ConsumerRecord<byte[], byte[]> receive() {
var timer = time.timer(timeoutMs);
while (!recordIter.hasNext()) {
recordIter =
consumer.poll(Duration.ofMillis(timer.remainingMs())).iterator();
timer.update();
if (!recordIter.hasNext() && timer.isExpired()) {
throw new TimeoutException();
}
}
return recordIter.next();
}
{code}
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)