Orleans 1.5.2 - Grain doesn't de-activate on InconsistentStateException from timer tick
Hi, I have a grain that performs periodic work using a grain timer (not reminder), and I noticed in Orleans code that only grain messages are checked for InconsistentStateException in order to de-activate the grain, but for timer ticks it's not the case. I find it a bug since I expect the de-activation behavior to take place for timers as well.
Grain will deactivate because of inactivity, there could be other factors as well. As far as I know, an exception within grain should not prevent grain from deactivating. https://dotnet.github.io/orleans/Documentation/Advanced-Concepts/Activation-Garbage-Collection.html
I saw in Orleans code and release notes that if a grain message (API call/reminder/etc.) throws that exception then Orleans will de-activate the grain assuming storage conflict was caused by duplicate activation, so I expect Orleans to do the same if timers throw storage conflict even though they aren't considered a grain message
yes it is true that orleans will de-activate a gain if a grain message(API or reminder since reminder calls is implemented as a grain message) throws an InconsistentStateException. Reasoning behind it is better to reboot the grain if it is in a bad state.
My understanding of why timers doesn't do that is timers is specific to one activation. Since its scope is inside one activation, so philosophically it shouldn't affect that activation's de-activate logic. I suspect this isn't a bug, but by design. But I'm not that familiar with timer's history, let me summon @sergeybykov for more information.
@sergeybykov the question, by design, should grain de-activate if its timer throw a InconsistentStateException?
This looks like a bug to me. I think we should deactivate a grain upon an unhandled InconsistentStateException thrown from a timer callback just like we do grain method calls. Otherwise, the grain may get 'stuck' in that state for a long time.
Looking at this, and considering short term work arounds - is there a disadvantage to handling this logic in Grain.WriteStateAsync itself? https://github.com/dotnet/orleans/blob/d360b539784b14a73ceb357fd6b5084d3116e9d9/src/Orleans.Core.Abstractions/Core/Grain.cs#L308
protected virtual Task WriteStateAsync()
{
try {
return storage.WriteStateAsync();
} catch (InconsistentStateException e) {
this.DeactivateOnIdle();
throw;
}
}
Then the logic here https://github.com/dotnet/orleans/blob/00fac09a241526dbcad2e298ded71481578dc20b/src/Orleans.Runtime/Core/InsideRuntimeClient.cs#L349 wouldn't be needed, and you could likely remove the complexity of IsSourceActivation.
The workaround should work I think.
@sergeybykov - more than just a workaround, could / should this change be made in Orleans?
If we were to do that as a general solution at the storage layer, that would prevent application code from handling InconsistentStateException in a different manner. I'm afraid that would be too limiting.
We've moved this issue to the Backlog. This means that it is not going to be worked on for the coming release. We review items in the backlog at the end of each milestone/release and depending on the team's priority we may reconsider this issue for the following milestone.