Closed pierDipi closed 2 years ago
@tsegismont @ppatierno what do you think about the proposed patch?
I believe it is a good idea to catch KafkaException
, but not just any Throwable
(including, e.g, OutOfMemoryError
).
Then in the implementation there is room for improvement, I think.
You could do (I haven't checked if this compiles but you'll get the idea):
@Override
public Future<Void> close() {
ContextInternal ctx = (ContextInternal) this.context;
if (this.closed.compareAndSet(false, true)) {
Promise<Void> promise = ctx.promise();
// Call wakeup before closing the consumer, so that existing tasks in the executor queue will
// wake up while we wait for processing the below added "close" task.
this.consumer.wakeup();
this.worker.submit(() -> {
try {
this.consumer.close();
promise.complete();
} catch (KafkaException ex) {
promise.fail(ex);
}
});
return promise.future().onComplete(v-> this.worker.shutdownNow());
}
return ctx.succeededFuture();
}
@Override
public void close(Handler<AsyncResult<Void>> completionHandler) {
Future<Void> future = close();
if (completionHandler != null) {
future.onComplete(completionHandler);
}
}
Thanks Thomas! I will send a PR based on your suggestion
Version
Which version(s) did you encounter this bug ? 4.2.5
Context
When closing the underlying Kafka consumer fails for some reason, the returned future is never complete.
Do you have a reproducer?
This test will produce timeout errors since the
Future<Void>
as defined like thisf = KafkaReadStream.close()
will never be complete:Steps to reproduce
Extra
Possible patch