[ 
https://issues.apache.org/jira/browse/KAFKA-3491?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15223656#comment-15223656
 ] 

Guozhang Wang commented on KAFKA-3491:
--------------------------------------

If we do not want to enforce users to keep track of a "failed" flag in their 
code, then calling "close(true)" in catch block and then "close()" in the 
finally block seems to be the only viable solution; however, I feel this is 
similar to calling "unsubscribe()" in catch block, and then "close()" in the 
finally block. And educating people of the "unsubscribe()" pattern may be less 
confusing.

About whether we should enforce users to keep track of the flag, I am a bit on 
the fence of that. In addition requiring the flag in a close() call seems not a 
common pattern in other Kafka clients as well. So I would prefer still keeping 
the "unsubscribe()" pattern with better docs.

> Issue with consumer close() in finally block with 'enable.auto.commit=true'
> ---------------------------------------------------------------------------
>
>                 Key: KAFKA-3491
>                 URL: https://issues.apache.org/jira/browse/KAFKA-3491
>             Project: Kafka
>          Issue Type: Bug
>          Components: consumer
>    Affects Versions: 0.9.0.0, 0.9.0.1
>            Reporter: dan norwood
>            Assignee: Jason Gustafson
>            Priority: Minor
>
> imagine you have a run loop that looks like the following:
> {code:java}
>   public void run() {
>     try {
>       consumer.subscribe(topics);
>       while (true) {
>         ConsumerRecords<K, V> records = consumer.poll(Long.MAX_VALUE);
>         records.forEach(record -> process(record));
>       }
>     } catch (WakeupException e) {
>       // ignore, we're closing
>     } catch (Exception e) {
>       log.error("Unexpected error", e);
>     } finally {
>       consumer.close();
>     }
>   }
> {code}
> if you run this with 'enable.auto.commit=true' and throw an exception in the 
> 'process()' method you will still try to commit all the read, but 
> unprocessed, offsets in the most recent batch.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to