Timeout exception on StopPrimarySilo when using persistent streams
Hi,
when stopping a primary silo (I have only two silos in my test) the execution hangs in Silo.Terminate method in step 9 (closing stream providers). This happens only when I use persistent streams (any).
I was able to track the issue to GrainBasedPubSubRuntime.UnregisterProducer, which should call PubSubRendezvousGrain.UnregisterProducer but this call never happens.
The following exception is logged when the method is called:
Silo S127.0.0.1:29668:232613388 is rejecting message: Request S127.0.0.1:29668:232613388Catalog@S0000000e->S127.0.0.1:29669:232613395DirectoryService@S0000000a #208: global::Orleans.Runtime.IRemoteGrainDirectory:LookupAsync(). Reason = Recent (00:00:00.0010001 ago, at 2017-05-16 06:56:06.488 GMT) connection failure trying to reach target silo S127.0.0.1:29669:232613395. Going to drop Request msg 208 without sending. CONNECTION_RETRY_DELAY = 00:00:01.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Orleans.Runtime.GrainDirectory.LocalGrainDirectory.<LookupAsync>d__113.MoveNext() in C:\Users\MO185073\Projects\orleans-1.4.1\src\OrleansRuntime\GrainDirectory\LocalGrainDirectory.cs:line 895
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Orleans.Runtime.Scheduler.SchedulerExtensions.<>c__DisplayClass0_0`1.<<QueueTask>b__0>d.MoveNext() in C:\Users\MO185073\Projects\orleans-1.4.1\src\OrleansRuntime\Scheduler\ShedulerExtensions.cs:line 16
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Orleans.Runtime.Placement.RandomPlacementDirector.<OnSelectActivation>d__1.MoveNext() in C:\Users\MO185073\Projects\orleans-1.4.1\src\OrleansRuntime\Placement\RandomPlacementDirector.cs:line 14
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Orleans.Runtime.Placement.PlacementDirectorsManager.<SelectOrAddActivation>d__6.MoveNext() in C:\Users\MO185073\Projects\orleans-1.4.1\src\OrleansRuntime\Placement\PlacementDirectorsManager.cs:line 59
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Orleans.Runtime.Dispatcher.<AddressMessage>d__30.MoveNext() in C:\Users\MO185073\Projects\orleans-1.4.1\src\OrleansRuntime\Core\Dispatcher.cs:line 585
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Orleans.Runtime.Dispatcher.<AsyncSendMessage>d__27.MoveNext() in C:\Users\MO185073\Projects\orleans-1.4.1\src\OrleansRuntime\Core\Dispatcher.cs:line 538
From this point forward nothing happens and I have to keep waiting for 10 minutes for the timeout exception.
After spending ton of time debugging and looking through the issues here I found a workaround, which works. Simply stop the stream provider before stopping the silos:
_cluster?
.GrainFactory
.GetGrain<IManagementGrain>(0)
.SendControlCommandToProvider(
"Orleans.Streams.RabbitMqStreamProvider",
Globals.StreamProviderName,
(int) PersistentStreamProviderCommand.StopAgents)
.Wait();
_cluster?.StopAllSilos();
I think the call to PubSubRendezvousGrain requires messaging to work, but it was disabled in some earlier step in Silo.Terminate.
Is this expected, or a bug?
Thank you, Martin
I may be stating obvious here, but also when I use StreamPubSubType.ImplicitOnly instead of the default, this issue doesn't happen.
I think you are correct, call to PubSubRendezvousGrain requires grain message to work, which might be affected when you terminate the primary silo. It doesn't happen with StreamPubSubType.ImplicitOnly is because ImplicitOnly doesn't use PubSubRendezvousGrain to manage publish/subscription map, the pubsub map is built from ImplicitStreamSubscription attribute on grain classes.
More details on ImplicitOnly so that I don't confuse you, when you use StreamPubSubType.ImplicitOnly , it only supports implicit subscribe. How implicit subscribe work is: on silo start up, it builds ImplicitStreamSubscriberTable from grain classes' ImplicitStreamSubscription attribute. ImplicitStreamSubscriberTable is not a grain, ImplicitStreamSubscriberTable is just an object in memory in every silo. When a producer register as a producer on a stream, it will calls into ImplicitPubSub and gets a list of subscriber back from ImplicitStreamSubscriberTable, on which it can produce on. So when it calls UnRegisterProducer into ImplicitPubsub, ImplicitPubsub actually didn't do anything, other than return a TaskDone.Done
I think the problem you saw is definitely not a good behavior, and can be simply solved by improving silo shut down process, which is to put the step of shut down pulling agents in front of deactivate all grain activations.
The root cause of this bad behavior is, in silo shut down process, deactivation grain activations (including PubSubRendezvousGrain ) is in front of stream provider clean up. In Stream provider clean up step, each stream provider will call into its local pullingAgentManager in current silo to ask it to stop any agents it is managing. But pulling agent is a producer in streaming system too. So in a pulling agent's shut down process, it will call into the PubSubRendezvousGrain to request a unregister, while the grain is already deactivated.
So I think the fix here is, in silo shutdown process, find a way to get the pullingAgentManager and use it to shut down any agents it is managing, before grain deactivating step.
But I don't have bandwidth to fix it right now, do you have bandwidth to fix it? I will put it into backlog first.
This only applies to test cases, when you have a primary silo. In the regular case this will not be a problem, since if this grain is deactivated, it will be reactivated on another silo. Only in test, since you shut down the primary silo, nothing else can work after that.
You can either solve it for test only case, or simply shorten the timeout.
I don't think you want to change the shutdown sequence just like that. There is a lot of dependancies and different scenarios that rely on this order. So you would want to think hard through them before changing it.
I think it applies to both test case and regular case, just it happens more to test cases, and happen much less to regular case. Yes a grain can be reactivated on another silo, but what if the whole cluster is shutting down?
And I agree we should think through different scenarios before making change to shutdown sequence. And shutdown sequence is like that for variety of reasons. But isn't this edge case one of a new scenario which we should think through?
I guess another question is: are you trying to fix it for test cases or regular case? If you just want to fix it for test case, then in TestCluster stop silo process, apply stop agent step in a proper order. In this way, we won't be changing shut down sequence in regular case.