azure-sdk-for-net
azure-sdk-for-net copied to clipboard
EventData Data property is null
Library name and version
Azure.Messaging.EventHubs 5.10.0.0
Query/Question
Hi, we have the following piece of code throwing NullReferenceExceptions suddenly in large amounts:
if (eventArgs.Data.Properties.ContainsKey(CommonConstants.EventType))
Judging from the code, the only thing that can be null there is Data property. I can see that in the XML documentation on that property there's a note:
Expected to be null if the receive call has timed out.
Could you please elaborate on this, what this means and what is receive timeout and how we can try to reproduce it? Or if you have any ideas why this might be happening it would be helpful.
Environment
No response
Thank you for your feedback. Tagging and routing to the team member best able to assist.
Hi @ewancoder. This is known and intentional behavior when you set EventProcessorClientOptions.MaximumWaitTime. This tells the processor to wait for that interval and when no events are available from that partition, emit an empty call to your handler. This is often used by applications as a heartbeat mechanism to help detect when events are not flowing through the system.
More discussion and context can be found in the Event Processor Handlers sample.
Hi @ewancoder. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.
Oh thanks, this seems to be the root cause indeed. Let me investigate a bit more in that direction and I'll get back to you.
So, in regards to the issue above, if we ignore all events that have null args.Data property, but are still processing the ones that have Data set, we aren't actually losing any data. The large amount of them just means that we have a short timeout set up and a lack of events in the hub, so a lot of empty "fake" events are being generated by the library but no real data is at risk. Right?
So, in regards to the issue above, if we ignore all events that have null args.Data property, but are still processing the ones that have Data set, we aren't actually losing any data. The large amount of them just means that we have a short timeout set up and a lack of events in the hub, so a lot of empty "fake" events are being generated by the library but no real data is at risk. Right?
Correct. There is no data loss in this scenario. If you are not interested in receiving empty pings, I'd suggest setting the MaximumWaitTIme on the options to null.
Is there a possibility that after reading EventArgs.Data.Body.Span, the Data property becomes null and HasEvent becomes false? We encounter a very strange error that the Data property that was previously not null might be becoming null, after upgrading to .NET 8 (5.6.2.0 -> 5.10.0.0 version of EventHub library)
The ProcessEventArgs structure is not mutable; there's no way that the value of Data can change under normal circumstances. For it to do so, you'd have to drop down to reflection and alter the private backing field.
Yeah I see, thanks. I'll keep digging then.
btw if we do use MaximumWaitTime, the empty event will come to every Partition, right? even if one instance of a service is handling multiple partitions, it will get called multiple times with different partitions
btw if we do use
MaximumWaitTime, the empty event will come to every Partition, right? even if one instance of a service is handling multiple partitions, it will get called multiple times with different partitions
This is correct. It applies to the processor itself and will impact any partitions owned by that processor instance.
Thanks for the help. I think we can close this as I think the issue was on our side after all.