Skip to content

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

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from

Conversation

satvu
Copy link
Member

@satvu satvu commented Jul 2, 2025

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.

  • Backporting to the in-proc branch is not required
    • Otherwise: Link to backporting PR
  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • My changes do not require diagnostic events changes
    • Otherwise: I have added/updated all related diagnostic events and their documentation (Documentation issue linked to PR)
  • I have added all required tests (Unit tests, E2E tests)

Additional information

Additional PR information

@satvu satvu changed the title Worker channel crash Fail in-flight invocations when worker channel restarts Jul 2, 2025
@fabiocav fabiocav requested a review from Copilot July 2, 2025 23:35
Copilot

This comment was marked as outdated.

@satvu satvu changed the title Fail in-flight invocations when worker channel restarts Fail in-flight invocations when worker channel shuts down Jul 8, 2025
@satvu satvu requested a review from Copilot July 9, 2025 01:18
Copilot

This comment was marked as outdated.

@satvu satvu marked this pull request as ready for review July 10, 2025 20:38
@satvu satvu requested a review from a team as a code owner July 10, 2025 20:38
[InlineData(3, true)]
[InlineData(1, false)]
[InlineData(3, false)]
public async Task Shutdown_FailsInFlightInvocations(int numberOfInvocations, bool hasFailureException)
Copy link
Member Author

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.

@satvu satvu requested review from kshyju, fabiocav and Copilot July 16, 2025 01:44
Copy link
Contributor

@Copilot Copilot AI left a 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 with Shutdown 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

Comment on lines 42 to +46
for (int attemptCount = 1; attemptCount <= MaxRetries; attemptCount++)
{
try
{
if (resultSource is not null && resultSource.Task.IsFaulted)
Copy link
Preview

Copilot AI Jul 16, 2025

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.

Suggested change
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.

Copy link
Member Author

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.

@@ -1555,21 +1556,21 @@ public bool IsExecutingInvocation(string invocationId)
return _executingInvocations.ContainsKey(invocationId);
}

public bool TryFailExecutions(Exception workerException)
public void Shutdown(Exception workerException)
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Worker restart due to function timeout does not fail current executions
3 participants