Couldn't stop Subscription in time

In the dispatcher, There are following three methods,

public void Start()

{

Restart();

}

public void Stop()

{

try

{

logger.Info(“Stopping service…”);

if (catchUpSubscription != null && catchUpSubscription.IsSubscribedToAll)

{

catchUpSubscription.Stop(TimeSpan.FromSeconds(10));

}

logger.Info(“Service stopped.”);

}

catch (TimeoutException exception)

{

logger.Error(exception);

}

}

private void Restart()

{

lastPosition = PreparePosition(tracker.GetPosition());

logger.InfoFormat(“Starting subscription from:{0}”, lastPosition);

catchUpSubscription = connection.SubscribeToAllFrom(

lastPosition,

false,

EventAppeared,

null,

SubscriptionDropped);

}

``

This dispatcher is a part of a windows service developed using TopShelf.

On starting the windows service, it calls the start method and the dispatcher starts dispatching events.

When the windows service is stopped, it calls the Stop method on the dispatcher that throws following error:

Stopping service…

System.TimeoutException: Couldn’t stop EventStoreAllCatchUpSubscription in time.

at EventStore.ClientAPI.EventStoreCatchUpSubscription.Stop(TimeSpan timeout)

at EventDispatcherService.EventDispatcher.Stop()

System.TimeoutException: Couldn’t stop EventStoreAllCatchUpSubscription in time.

at EventStore.ClientAPI.EventStoreCatchUpSubscription.Stop(TimeSpan timeout)

at EventDispatcherService.EventDispatcher.Stop()

Even after increasing the timeout period, it does not stop the subscription, rather it times out each time.

What is wrong with the code? why the subscription does not stop normally?, I am using V2.0.2.0 of the eventstoreclient API.

I believe this was a bug (I remember fixing it I think). Try 3.0 my
guess us the issue will no longer happen.

Cheers,

Greg

I had the same problems when trying to invoke the Subscription.Stop method from inside the EventAppeared handler, thus causing a deadlock or something. Try the Stop method overload without a timeout, it works differently (but you need to upgrade, V2.0.2.0 didnt have it) and should resolve your problem.

Thank you Greg, I will try 3.0.

Thank you nmehlei.