Error with embedded store subscriptions

I have an integration test that fails roughly 1 in 5 times. It fails because the subscription gets dropped. Here is the log:

[27,15:38:48.172,DEBUG] Catch-up Subscription to $ce-Foo: starting…
[27,15:38:48.173,DEBUG] Catch-up Subscription to $ce-Bar: starting…
[28,15:38:48.177,DEBUG] Catch-up Subscription to $ce-Foo: running…
[32,15:38:48.177,DEBUG] Catch-up Subscription to $ce-Bar: running…
[32,15:38:48.178,DEBUG] Catch-up Subscription to $ce-Bar: pulling events…
[28,15:38:48.177,DEBUG] Catch-up Subscription to $ce-Foo: pulling events…
[32,15:38:48.229,DEBUG] Catch-up Subscription to $ce-Bar: finished reading events, nextReadEventNumber = 0.
[28,15:38:48.229,DEBUG] Catch-up Subscription to $ce-Foo: finished reading events, nextReadEventNumber = 0.
[28,15:38:48.229,DEBUG] Catch-up Subscription to $ce-Foo: subscribing…
[32,15:38:48.229,DEBUG] Catch-up Subscription to $ce-Bar: subscribing…
[32,15:38:48.236,DEBUG] Catch-up Subscription to $ce-Bar: dropping subscription, reason: CatchUpError System.NullReferenceException: Object reference not set to an instance of an object.
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value)
at EventStore.ClientAPI.Embedded.EmbeddedSubcriptionsManager.StartSubscription(Guid correlationId, IEmbeddedSubscription subscription)
at EventStore.ClientAPI.Embedded.EmbeddedSubscriber.StartSubscription(Guid correlationId, TaskCompletionSource1 source, String stream, UserCredentials userCredentials, Boolean resolveLinkTos, Action2 eventAppeared, Action3 subscriptionDropped) at EventStore.ClientAPI.Embedded.EventStoreEmbeddedNodeConnection.SubscribeToStreamAsync(String stream, Boolean resolveLinkTos, Action2 eventAppeared, Action`3 subscriptionDropped, UserCredentials userCredentials)
at EventStore.ClientAPI.EventStoreCatchUpSubscription.b__0(Object _).

``

I’ve tried adding a subscriptionDropped delegate to re-subscribe, but this doesn’t appear to fire.

Any ideas?

Can you confirm version/runtime etc? I am looking at the code and not
seeing how this would fail
https://github.com/EventStore/EventStore/blob/release-v3.4.0/src/EventStore.ClientAPI.Embedded/EmbeddedSubcriptionsManager.cs#L22

The version of the embedded client dll is 3.3.1

windows .net 4.5?

Yep

Its a bit baffling how that could fail, do you get the same issue with
only a single subscription? Thinking maybe a threading issue on the
grow of dict.

I had a mistake with the subscriptionDropped delegate, I wasn’t passing it in. With the delegate passed in, I can’t replicate the failure, even when the delegate is doing nothing.

Yeah, threading probably the cause. Maybe make it a concurrent dictionary.

done. https://github.com/EventStore/EventStore/pull/740

Awesome :slight_smile: