orleans icon indicating copy to clipboard operation
orleans copied to clipboard

Orleans 1.5.2 bug - GrainStateStorageBridge loses exception callstack

Open Eldar1205 opened this issue 8 years ago • 6 comments

Hi,

I've looked into code of GrainStateStorageBridge and in the method WriteStateAsync found that if an OrleansException is caught is won't be wrapped in an OrleansException and will later thrown as is in a way that loses the original callstack, which is a bug:

public async Task WriteStateAsync()
    {
      Stopwatch sw = Stopwatch.StartNew();
      GrainReference grainRef = this.baseGrain.GrainReference;
      Exception exception;
      try
      {
        await this.store.WriteStateAsync(this.grainTypeName, grainRef, this.statefulGrain.GrainState);
        StorageStatisticsGroup.OnStorageWrite(this.store, this.grainTypeName, grainRef, sw.Elapsed);
        exception = (Exception) null;
      }
      catch (Exception ex)
      {
        exception = ex;
      }
      if (exception != null)
      {
        StorageStatisticsGroup.OnStorageWriteError(this.store, this.grainTypeName, grainRef);
        string message = this.MakeErrorMsg("WriteState", exception);
        this.store.Log.Error(102203, message, exception);
        if (!(exception is OrleansException))
          exception = (Exception) new OrleansException(message, exception);
      }
      sw.Stop();
      if (exception != null)
        throw exception;
    }

Eldar1205 avatar Jun 07 '18 16:06 Eldar1205

I'm a little lost. OrleansException will lose the original call stack if it didnt wrap a innerException, which is supposed to be the original exception. Is this correct? If yes, then this has nothing to do with GrainStateStorageBridge, but with how the original OrleansException is generated. Right ?

Please correct me if I understand something terribly wrong.

xiazen avatar Jun 08 '18 21:06 xiazen

Is the issue here that if the caught exception is an OrleansException instead of doing throw from within the catch block we do throw exception from outside of it, and hence losing the call stack?

sergeybykov avatar Jun 08 '18 23:06 sergeybykov

Exactly

On Jun 9, 2018 2:39 AM, "Sergey Bykov" [email protected] wrote:

Is the issue here that if the caught exception is an OrleansException instead of doing throw from within the catch block we do throw exception from outside of it, and hence losing the call stack?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dotnet/orleans/issues/4662#issuecomment-395919779, or mute the thread https://github.com/notifications/unsubscribe-auth/AFBYt_XsxFwVlxunlg47kQdis29C7cTlks5t6wsrgaJpZM4Uet8W .

Eldar1205 avatar Jun 08 '18 23:06 Eldar1205

ohhhhhh hence losing the original call stack. sorry I was being silly. If we move the LOGIC in


 if (exception != null)
      {
        StorageStatisticsGroup.OnStorageWriteError(this.store, this.grainTypeName, grainRef);
        string message = this.MakeErrorMsg("WriteState", exception);
        this.store.Log.Error(102203, message, exception);
        if (!(exception is OrleansException))
          exception = (Exception) new OrleansException(message, exception);
      }
      sw.Stop();
      if (exception != null)
        throw exception;

back to the catch block, then we should be fine right?

xiazen avatar Jun 09 '18 00:06 xiazen

I think the stopwatch is the reason the code is outside the catch block, can be refactored to a finally clause

On Jun 9, 2018 3:16 AM, "Xiao Zeng" [email protected] wrote:

ohhhhhh hence losing the original call stack. sorry I was being silly. If we move the

if (exception != null) { StorageStatisticsGroup.OnStorageWriteError(this.store, this.grainTypeName, grainRef); string message = this.MakeErrorMsg("WriteState", exception); this.store.Log.Error(102203, message, exception); if (!(exception is OrleansException)) exception = (Exception) new OrleansException(message, exception); } sw.Stop(); if (exception != null) throw exception;

back to the catch block, then we should be fine right?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dotnet/orleans/issues/4662#issuecomment-395923993, or mute the thread https://github.com/notifications/unsubscribe-auth/AFBYt0leAkazYJ8IhaSKj6KBWv2FplNfks5t6xPugaJpZM4Uet8W .

Eldar1205 avatar Jun 09 '18 00:06 Eldar1205

This is fixed in 2.0, does this warrant a 1.5.x patch release? We can reopen if so.

ReubenBond avatar Jun 25 '18 22:06 ReubenBond