ah- / rdkafka-dotnet

C# Apache Kafka client
Other
242 stars 73 forks source link

Does disposing a Handle guarantee no more callbacks? #44

Closed MaximGurschi closed 8 years ago

MaximGurschi commented 8 years ago

Hello,

I looked at the RdKafka code and i believe that disposing a Handle (producer/(event)consumer) means that there will be no subsequent callbacks (OnError, OnPartitionsAssigned, LogCallbacks, etc.). Can you please confirm if the above is correct and will stay like that?

I just want to make sure that I do not need to protect against subsequent callbacks after calling Dispose.

ah- commented 8 years ago

Yes. Callbacks only run in Tasks controlled by C# and those are shut down during Dispose.

See for example https://github.com/ah-/rdkafka-dotnet/blob/master/src/RdKafka/Handle.cs#L72.

Edit: Almost, LogCallback are currently different. They're the only callback that's invoked directly from librdkafka without going via a queue/poll. I'm not sure if the LogCallback is ever actually called after rd_kafka_destroy, but it is theoretically possible.

MaximGurschi commented 8 years ago

Ok thank you for that.

MaximGurschi commented 8 years ago

To conclude - from Magnus:

_Logs may be emitted until rd_kafkadestroy() returns, but not after that. The reason for this is that quite a lot of stuff might go on decommissioning librdkafka and thus logs are usable to find errors or for debugging.

That is good enough for me!

ah- commented 8 years ago

Thanks for investigating.

So the final answer is: Yes, disposing a handle guaratees that no more callbacks are invoked after Dispose returns.