Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 49 additions & 9 deletions src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,8 @@
// - a timeout
// - an out of memory exception
// - a worker process exit
if (functionResult.Exception is Host.FunctionTimeoutException
|| functionResult.Exception?.InnerException is SessionAbortedException // see RemoteOrchestrationContext.TrySetResultInternal for details on OOM-handling
|| (functionResult.Exception?.InnerException?.GetType().ToString().Contains("WorkerProcessExitException") ?? false))
{
// TODO: the `WorkerProcessExitException` type is not exposed in our dependencies, it's part of WebJobs.Host.Script.
// Should we add that dependency or should it be exposed in WebJobs.Host?
if (this.IsPlatformLevelError(functionResult))
{

Check failure on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / build

Check failure on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / build

Check warning on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / e2e-dts

Check warning on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / e2e-dts

Check warning on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / e2e-azurestorage-linux

Check warning on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / e2e-azurestorage-linux

Check warning on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / build

Check warning on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / e2e-mssql

Check warning on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / e2e-mssql

Check warning on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / build

Check warning on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / e2e-azurestorage-windows

Check warning on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / e2e-azurestorage-windows

Check warning on line 180 in src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs

View workflow job for this annotation

GitHub Actions / build

throw functionResult.Exception;
}
}
Expand All @@ -205,9 +201,9 @@
OrchestratorExecutionResult orchestratorResult;
if (functionResult.Succeeded)
{
if (workerRequiresHistory)
{
throw new SessionAbortedException("The worker has since ended the extended session and needs an orchestration history to execute the orchestration request.");
if (workerRequiresHistory)
{
throw new SessionAbortedException("The worker has since ended the extended session and needs an orchestration history to execute the orchestration request.");
}

orchestratorResult = context.GetResult();
Expand Down Expand Up @@ -295,6 +291,40 @@
dispatchContext.SetProperty(orchestratorResult);
}

private bool IsPlatformLevelError(FunctionResult functionResult)
{
if (this.ExceptionIsInstanceOrIsCausedBy(functionResult.Exception, checkType: typeof(Host.FunctionTimeoutException))
|| this.ExceptionIsInstanceOrIsCausedBy(functionResult.Exception, checkType: typeof(SessionAbortedException)) // see RemoteOrchestrationContext.TrySetResultInternal for details on OOM-handling
|| this.ExceptionIsInstanceOrIsCausedBy(functionResult.Exception, checkTypeString: "WorkerProcessExitException"))
{
// TODO: the `WorkerProcessExitException` type is not exposed in our dependencies, it's part of WebJobs.Host.Script.
// Should we add that dependency or should it be exposed in WebJobs.Host?
return true;
}

return false;
}

private bool ExceptionIsInstanceOrIsCausedBy(Exception? sourceException, Type? checkType = null, string? checkTypeString = null)
{
if (sourceException is null)
{
return false;
}

if (checkType != null && sourceException.GetType().IsAssignableFrom(checkType))
{
return true;
}

if (checkTypeString != null && sourceException.GetType().ToString().Contains(checkTypeString))
{
return true;
}

return this.ExceptionIsInstanceOrIsCausedBy(sourceException.InnerException, checkType, checkTypeString);
}

/// <summary>
/// Durable Task Framework entity middleware that invokes an out-of-process orchestrator function.
/// </summary>
Expand Down Expand Up @@ -401,6 +431,11 @@
// Re-throw so we can abort this invocation.
this.HostLifetimeService.OnStopping.ThrowIfCancellationRequested();
}

if (this.IsPlatformLevelError(functionResult))
{
throw functionResult.Exception;
}
}
catch (Exception hostRuntimeException)
{
Expand Down Expand Up @@ -545,6 +580,11 @@
// Re-throw so we can abort this invocation.
this.HostLifetimeService.OnStopping.ThrowIfCancellationRequested();
}

if (this.IsPlatformLevelError(result))
{
throw result.Exception;
}
}
catch (Exception hostRuntimeException)
{
Expand Down
Loading