Aeron.NET
Aeron.NET copied to clipboard
NullReferenceException when using CloseHandler
Connecting with a CloseHandler passed via the Context causes a NullReferenceException:
var ctx = new Aeron.Context()
.CloseHandler(() => { });
var aeron = Aeron.Connect(ctx);
causes a NullReferenceException here:
Adaptive.Aeron.dll!Adaptive.Aeron.Aeron.NextCorrelationId() Line 347
Adaptive.Aeron.dll!Adaptive.Aeron.ClientConductor.ClientConductor(Adaptive.Aeron.Aeron.Context ctx, Adaptive.Aeron.Aeron aeron) Line 127
Adaptive.Aeron.dll!Adaptive.Aeron.Aeron.Aeron(Adaptive.Aeron.Aeron.Context ctx) Line 68
Adaptive.Aeron.dll!Adaptive.Aeron.Aeron.Connect(Adaptive.Aeron.Aeron.Context ctx) Line 117
The reason seems to be that the ClientConductor ctor tries to get a NextCorrelationId(), but this in turn needs the Aeron._clientConductor that has not been constructed yet and is still null.
Note: A workaround for this is to not use the Context.CloseHandler() but instead use Aeron.AddCloseHandler() after connecting. I noticed the issue when upgrading from 1.29.0 to 1.39.0, so it must have been introduced between those versions.