Skip to content

Commit

Permalink
Ensure function abort on shutdown (#2456) (#2477)
Browse files Browse the repository at this point in the history
  • Loading branch information
jviau committed May 16, 2023
1 parent 31e3c92 commit 3a8795d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

### Bug Fixes

- Fix connection exhaustion and memory leak due to incorrect caching of `DurableTaskClient`'s in dotnet isolated extension.
- Fix handling of in-flight orchestrations and activities during host shutdown.
- Previously these were considered "failed", now they will be retried.
- This only affected dotnet-isolated and java workers.

### Breaking Changes

Expand Down
14 changes: 13 additions & 1 deletion src/WebJobs.Extensions.DurableTask/OutOfProcMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public async Task CallOrchestratorAsync(DispatchMiddlewareContext dispatchContex
context.SetResult(
response.Actions.Select(ProtobufUtils.ToOrchestratorAction),
response.CustomStatus);
#pragma warning restore CS0618 // Type or member is obsolete (not intended for general public use)
},
#pragma warning restore CS0618 // Type or member is obsolete (not intended for general public use)
};

FunctionResult functionResult;
Expand All @@ -145,6 +145,12 @@ public async Task CallOrchestratorAsync(DispatchMiddlewareContext dispatchContex
functionResult = await function.Executor.TryExecuteAsync(
input,
cancellationToken: this.HostLifetimeService.OnStopping);
if (!functionResult.Succeeded)
{
// Shutdown can surface as a completed invocation in a failed state.
// Re-throw so we can abort this invocation.
this.HostLifetimeService.OnStopping.ThrowIfCancellationRequested();
}
}
catch (Exception hostRuntimeException)
{
Expand Down Expand Up @@ -295,6 +301,12 @@ public async Task CallActivityAsync(DispatchMiddlewareContext dispatchContext, F
result = await function.Executor.TryExecuteAsync(
triggerInput,
cancellationToken: this.HostLifetimeService.OnStopping);
if (!result.Succeeded)
{
// Shutdown can surface as a completed invocation in a failed state.
// Re-throw so we can abort this invocation.
this.HostLifetimeService.OnStopping.ThrowIfCancellationRequested();
}
}
catch (Exception hostRuntimeException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<RootNamespace>Microsoft.Azure.WebJobs.Extensions.DurableTask</RootNamespace>
<MajorVersion>2</MajorVersion>
<MinorVersion>9</MinorVersion>
<PatchVersion>4</PatchVersion>
<PatchVersion>5</PatchVersion>
<Version>$(MajorVersion).$(MinorVersion).$(PatchVersion)</Version>
<FileVersion>$(MajorVersion).$(MinorVersion).$(PatchVersion)</FileVersion>
<AssemblyVersion>$(MajorVersion).0.0.0</AssemblyVersion>
Expand Down

0 comments on commit 3a8795d

Please sign in to comment.