orleans icon indicating copy to clipboard operation
orleans copied to clipboard

Orleans 1.5.2 - Grain doesn't de-activate on InconsistentStateException from timer tick

Open Eldar1205 opened this issue 8 years ago • 9 comments

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.

Eldar1205 avatar Jun 02 '18 03:06 Eldar1205

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

MittalNitish avatar Jun 03 '18 16:06 MittalNitish

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

Eldar1205 avatar Jun 03 '18 17:06 Eldar1205

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?

xiazen avatar Jun 08 '18 20:06 xiazen

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.

sergeybykov avatar Jun 11 '18 19:06 sergeybykov

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.

michaeltdaniels avatar Jun 24 '20 18:06 michaeltdaniels

The workaround should work I think.

sergeybykov avatar Jul 05 '20 22:07 sergeybykov

@sergeybykov - more than just a workaround, could / should this change be made in Orleans?

michaeltdaniels avatar Jul 07 '20 13:07 michaeltdaniels

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.

sergeybykov avatar Jul 08 '20 01:07 sergeybykov

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.

ghost avatar Mar 26 '22 01:03 ghost