Jroland / kafka-net

Native C# client for Kafka queue servers.
Apache License 2.0
482 stars 232 forks source link

SendMessageAsync of Producer not completing #115

Open garywlynn opened 6 years ago

garywlynn commented 6 years ago

I've run into an issue when sending a set of messages to producer.SendMessageAsync such that the await Task.WhenAll statement seems to drop out before the tasks are complete. The function returns "{not yet computed}" for the Result and "Waiting for Activation" for the status. I do know that the sending of the data was successful, because the full dataset appeared within my Kafka application.

My solution to this problem was to simply make a synchronous version of the SendMessage function with the following signature:

public List<ProduceResponse> SendMessage(string topic, IEnumerable<Message> messages, Int16 acks = 1, TimeSpan? timeout = null, MessageCodec codec = MessageCodec.CodecNone)

The only difference between this and the original function is that I used Task.WaitAll instead of await Task.WhenAll:

Task.WaitAll(batch.Select(x => x.Tcs.Task).ToArray());

So now the questions:

  1. Any idea as to the cause of the issue with the async version?
  2. Is this a good solution to the problem, or is there a better one?
  3. Should I submit this alternative function as a pull request?

Thanks much.

Gary Lynn