Producer.Dispose does not return after awaiting ProduceAsync
See original GitHub issueDescription
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:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@scharrenberg we’re impacted by this issue also, but managed to work around it by having
await Task.Yield()
immediately after the call toProduceAsync(...)
, as suggested initially in #92.yes, I checked this and it’s resolved.