confluentinc / confluent-kafka-dotnet

Confluent's Apache Kafka .NET client
https://github.com/confluentinc/confluent-kafka-dotnet/wiki
Apache License 2.0
2.78k stars 847 forks source link

Consumer.Close() blocks indefinitely after unhandled exception in PartitionsRevokedHandler #1280

Open Rytisk opened 4 years ago

Rytisk commented 4 years ago

Description

The issue I'm facing is that a call to consumer.Close() blocks indefinitely after an unhandled exception occurs inside PartitionsRevokedHandler.

Version: Confluent.Kafka = v1.4.2 OS: Windows 10

How to reproduce

static void Main(string[] args)
{
    var consumer = new ConsumerBuilder<string, string>(new ConsumerConfig 
    {
        EnableAutoOffsetStore = false,
        BootstrapServers = "...",
        GroupId = "group",
    }).SetPartitionsRevokedHandler((c, p) =>
    {
        throw new Exception(); //unhandled exception
    }).Build();

    consumer.Subscribe("topic");
    try 
    {
        while (true)
        {
            var msg = consumer.Consume(TimeSpan.FromSeconds(2));
        }
    }
    catch(Exception ex)
    {
        //catches the exception thrown in PartitionsRevokedHandler
        Console.WriteLine(ex); 
    }
    finally
    {
        //blocks indefinitely
        consumer.Close();
    }
}

Checklist

Please provide the following information:

mhowlett commented 4 years ago

the root cause of the problem is exceptions don't propagate through native code. in v1.4.0, Confluent.Kafka now handles this explicitly in the producer case, but it's not implemented for the consumer handlers. thanks for noting, we should fix this.

ajmlima commented 1 year ago

Is there any news about this? I'm facing this issue in v1.9.3