-
Notifications
You must be signed in to change notification settings - Fork 461
Fail in-flight invocations when worker channel shuts down #11159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
[InlineData(3, true)] | ||
[InlineData(1, false)] | ||
[InlineData(3, false)] | ||
public async Task Shutdown_FailsInFlightInvocations(int numberOfInvocations, bool hasFailureException) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prior to this change, calling TryFailExecutions
(replaced by Shutdown
) would not fail executions without an exception being passed in. This test makes sure that in-flight invocations are failed whether or not an exception is passed in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modifies the worker channel shutdown behavior to better handle in-flight invocations when a worker channel encounters a fatal error. The key change is replacing the TryFailExecutions
method with a more descriptive Shutdown
method that properly fails in-flight invocations with a specific exception type.
Key changes:
- Replace
TryFailExecutions
method withShutdown
method across all worker channel implementations - Introduce
WorkerShutdownException
to provide more specific error information for failed invocations - Update HTTP proxy service to properly handle worker shutdown scenarios during request retries
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
src/WebJobs.Script/Workers/Rpc/IRpcWorkerChannel.cs |
Updates interface to replace TryFailExecutions with Shutdown method |
src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs |
Implements new Shutdown method with WorkerShutdownException |
src/WebJobs.Script/Exceptions/WorkerShutdownException.cs |
Adds new exception type for worker shutdown scenarios |
src/WebJobs.Script/Http/RetryProxyHandler.cs |
Updates HTTP retry logic to handle worker shutdown exceptions |
src/WebJobs.Script/Http/ScriptInvocationRequestTransformer.cs |
Adds transformer to pass script invocation context through HTTP proxy |
src/WebJobs.Script/Http/DefaultHttpProxyService.cs |
Integrates new transformer and adds invocation context to HTTP requests |
for (int attemptCount = 1; attemptCount <= MaxRetries; attemptCount++) | ||
{ | ||
try | ||
{ | ||
if (resultSource is not null && resultSource.Task.IsFaulted) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is performed on every retry attempt inside the loop. Consider moving this check outside the retry loop or caching the Task.IsFaulted result to avoid repeated property access.
for (int attemptCount = 1; attemptCount <= MaxRetries; attemptCount++) | |
{ | |
try | |
{ | |
if (resultSource is not null && resultSource.Task.IsFaulted) | |
var isTaskFaulted = resultSource?.Task.IsFaulted ?? false; | |
for (int attemptCount = 1; attemptCount <= MaxRetries; attemptCount++) | |
{ | |
try | |
{ | |
if (isTaskFaulted) |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be checked before every retry.
test/WebJobs.Script.Tests/Handlers/WebScriptHostExceptionHandlerTests.cs
Show resolved
Hide resolved
@@ -1555,21 +1556,21 @@ public bool IsExecutingInvocation(string invocationId) | |||
return _executingInvocations.ContainsKey(invocationId); | |||
} | |||
|
|||
public bool TryFailExecutions(Exception workerException) | |||
public void Shutdown(Exception workerException) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A thought: Should Shutdown also dispose this instance? The (worker) process is removed/killed in Dispose
method code, and I see the callers of Shutdown
is explicitly calling Dispose
after calling Shutdown
. Wondering that should be part of Shutdown method itself.
Issue describing the changes in this PR
resolves #10936
Pull request checklist
IMPORTANT: Currently, changes must be backported to the
in-proc
branch to be included in Core Tools and non-Flex deployments.in-proc
branch is not requiredrelease_notes.md
Additional information
Additional PR information