NullReferenceException when Silo is configured to use EventHub
We're trying to use Orleans.ServiceBus.Providers and connect to EventHub.
After updating from 2.0.0 rc2 to 2.0.0 final the following is observed:
On silo startup we get this exception:
fail: Orleans.Streams.*stg/9217687724268098230/d77a92b6.series[103303]
QueueAdapterReceiver series-0-0x00000000 failed to Initialize.
System.NullReferenceException: Object reference not set to an instance of an object.
at Orleans.ServiceBus.Providers.EventHubCheckpointerFactory.Create(String partition)
at Orleans.ServiceBus.Providers.EventHubAdapterReceiver.<Initialize>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Orleans.OrleansTaskExtentions.<SafeExecute>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Orleans.OrleansTaskExtentions.<LogException>d__9.MoveNext()
then finally the log is filled with these:
fail: Orleans.Streams.*stg/11935023428790472333/f3054e8d.series[103312]
Giving up reading from queue series-1 after retry attempts 6
System.NullReferenceException: Object reference not set to an instance of an object.
at Orleans.ServiceBus.Providers.EventHubAdapterReceiver.GetMaxAddCount()
at Orleans.Streams.PersistentStreamPullingAgent.<AsyncTimerCallback>d__35.MoveNext()
This is the config (in f# I'm sorry):
module StreamConfig =
let configureEventHubOptions =
new Action<EventHubOptions>(fun options ->
options.ConnectionString <- "Endpoint=..."
options.ConsumerGroup <-"prsiloquestionmark" //https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-features
options.Path <- "series"
)
let configureDefaultCheckpointer =
new Action<AzureTableStreamCheckpointerOptions>(fun options ->
options.ConnectionString <- "DefaultEndpointsProtocol=..."
options.TableName <- "series"
options.PersistInterval <- TimeSpan.FromSeconds(10.)
)
...
.AddEventHubStreams("series", StreamConfig.configureEventHubOptions, StreamConfig.configureDefaultCheckpointer)
...
I'm not an expert on f#. So here is the guess. You should use UseEventHubCheckpointer extension method to configure AzureTableStreamCheckpointer. I think your code snip only configured AzureTableStreamCheckpointerOptions , but didn't inject AzureTableStreamCheckpointer into DI correctly. Use UseEventHubCheckpointer would do that for you.
And also, you should use the AddEventHubStream extension, which take a EventHubStreamConfigurator action instead of the one with just Action<EventHubOptions>. The latter one would just configures your stream provider with default components, where here you want to configure a check pointer.
Well as a matter of fact, the one with just Action<EventHubOptions> should be configuring the default check pointer.. but there's a bug there it isn't doing that now. I will fix it soon. For now use the first one.
Thanks for the fast response. I'll try and use the other extension.
actually I took my words back, there's no bug in the AddEventHubStream extension method public static ISiloHostBuilder AddEventHubStreams(
this ISiloHostBuilder builder,
string name, Action<EventHubOptions> configureEventHub, Action<AzureTableStreamCheckpointerOptions> configureDefaultCheckpointer) Your stream provider config seems fine.
Based on the exception you show me , the null reference exception is in EventHubCheckpointerFactory.Create, whose body is as follows
public Task<IStreamQueueCheckpointer<string>> Create(string partition)
{
return EventHubCheckpointer.Create(options, providerName, partition, this.clusterOptions.ServiceId.ToString(), loggerFactory);
}
so my wild guess is, did you configure your cluster with a ServiceId?
Your wild guess was indeed a lucky guess. I changed the config to include ServiceId and then:
info: Orleans.ServiceBus.Providers.EventHubAdapterReceiver.series.0[0]
Starting to read latest messages from EventHub partition series-0 at offset -1
I think that there should be some config validation to assure ServiceId is configured!
Thank you
I think that there should be some config validation to assure ServiceId is configured!
Yes, we'll have this addressed very soon. And probably will release a patch build with the fix, as it seems to trip people over too much.
the validator is added in #4450 .
Resolved via #4450.