question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Producer.Dispose does not return after awaiting ProduceAsync

See original GitHub issue

Description

In the code below the execution stops when leaving the using block. When pausing in Visual Studio the debugger reports two deadlocked tasks.

We derived the example below from the SimpleProducer example. We did not expect any significant difference in behavior, with reference to the producer documentation

How to reproduce

  • Create a producer in an using block.
  • Await call to ProduceAsync
  • Leave using block
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Confluent.Kafka;
using Confluent.Kafka.Serialization;

namespace ResourceTest
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            const string brokerList = "<broker-url>";
            const string topicName = "topic";

            var config = new Dictionary<string, object>
            {
                {"bootstrap.servers", brokerList}
            };

            PublishWithBlockingDispose(config, topicName).Wait();
        }

        private static async Task PublishWithBlockingDispose(Dictionary<string, object> config, string topicName)
        {
            using (var producer = new Producer<Null, string>(config, null, new StringSerializer(Encoding.UTF8)))
            {
                var deliveryReport =
                    await producer.ProduceAsync(topicName, null, "samplePayload").ConfigureAwait(false);
                Console.WriteLine($"Partition: {deliveryReport.Partition}, Offset: {deliveryReport.Offset}");
            }

            Console.WriteLine("Unreachable code");
        }
    }
}

Checklist

Confluent.Kafka nuget version: 0.11.2 Apache Kafka version: 0.11.0 Client configuration: See code example Operating system: Windows 10

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ig2rcommented, Oct 26, 2017

@scharrenberg we’re impacted by this issue also, but managed to work around it by having await Task.Yield() immediately after the call to ProduceAsync(...), as suggested initially in #92.

0reactions
mhowlettcommented, Dec 15, 2017

yes, I checked this and it’s resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my ProducerBuilder class's message in .Net Core ...
Produce method sends a message asynchronously and doesn't wait for the response - it returns immediately.
Read more >
Kafka .NET Client
The Task returned by ProduceAsync will not complete until the success (or otherwise) of the request is known. As such, await``ing the ``ProduceAsync...
Read more >
Interface IProducer<TKey, TValue> | Confluent.Kafka
Returns the number of events served since the last call to this method or if this method has not yet been called, over...
Read more >
.Net Publish to Kafka topic (efficiently) | by Jai Rathore ...
We have two methods here which can be used to publish message asynchronously, delegating the result to a delivery handle or can be...
Read more >
Building Reliable Kafka Producers and Consumers in .NET
Upon restart, the consumer will be indeterminate because it doesn't know whether it successfully committed the offsets. To resolve its state, it ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found