Skip to content

fix channel init/shutdown race - #11853

Merged
Brett Samblanet (brettsam) merged 5 commits into
devfrom
brettsam/fix-channel-shutdown-race
Jul 10, 2026
Merged

Brett Samblanet (brettsam) merged 5 commits into
devfrom
brettsam/fix-channel-shutdown-race

Conversation

@brettsam

@brettsam Brett Samblanet (brettsam) commented Jun 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes a WebHost RPC worker channel shutdown race where ShutdownChannelsAsync could wait forever on a worker channel that was added to the channel dictionary but had not finished initializing yet.

The race was exposed by explicitly stopping and disposing WebHost instances in E2E fixture cleanup. If shutdown removed the runtime entry while initialization was still in flight, the initialization continuation could no longer complete the pending channel task, leaving shutdown blocked.

Changes

  • Cancels pending worker channel initialization tasks during ShutdownChannelsAsync so shutdown does not wait indefinitely.
  • Disposes worker channels that finish initializing after shutdown has already removed their runtime entry.
  • Disposes channels whose worker startup faults or is canceled, preventing worker process leaks.
  • Adds a regression test for an uninitialized worker channel during shutdown.
  • Stops and disposes WebHost instances from E2E fixture cleanup to exercise the shutdown path more broadly.

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)

@brettsam
Brett Samblanet (brettsam) force-pushed the brettsam/fix-channel-shutdown-race branch from c264c36 to 63b1044 Compare June 30, 2026 18:35
@brettsam
Brett Samblanet (brettsam) marked this pull request as ready for review June 30, 2026 19:13
@brettsam
Brett Samblanet (brettsam) requested a review from a team as a code owner June 30, 2026 19:13
Copilot AI review requested due to automatic review settings June 30, 2026 19:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 addresses a shutdown/initialization race in WebHostRpcWorkerChannelManager where host teardown could hang indefinitely if a worker channel was added but never finished initializing (its TaskCompletionSource was never completed).

Changes:

  • Cancels in-flight channel initialization waiters during ShutdownChannelsAsync and disposes channels that complete initialization after shutdown has already removed their runtime entry.
  • Ensures channels are disposed when worker startup faults/cancels to prevent worker process leaks/hangs during teardown.
  • Adds a regression unit test for the uninitialized-channel shutdown case and updates E2E fixture cleanup to explicitly stop/dispose the WebHost.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/WebJobs.Script.Grpc/Rpc/WebHostRpcWorkerChannelManager.cs Adds cancellation/cleanup logic to prevent shutdown deadlocks and leaks when initialization races with teardown.
test/WebJobs.Script.Tests/Workers/Rpc/WebHostRpcWorkerChannelManagerTests.cs Adds a regression test for shutdown while a channel is still uninitialized.
test/WebJobs.Script.Tests.Integration/WebHostEndToEnd/EndToEndTestFixture.cs Stops/disposes WebHost during E2E fixture cleanup to exercise the shutdown path.
test/WebJobs.Script.Tests.Integration/WebHostEndToEnd/SamplesEndToEndTests_Node_MultipleProcessesNoBundle.cs Adds fixture override to stop/dispose WebHost in cleanup (now redundant with base fixture).
release_notes.md Adds a release note entry for the shutdown race fix.

Comment thread release_notes.md Resolved
@brettsam

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@brettsam

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@brettsam

Copy link
Copy Markdown
Member Author

Copilot resolve the merge conflicts in this pull request

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Copilot resolve the merge conflicts in this pull request

Merged dev into the branch — no conflicts, the merge completed cleanly (commit 14ef3b42).

@brettsam
Brett Samblanet (brettsam) merged commit 52642ad into dev Jul 10, 2026
11 checks passed
@brettsam
Brett Samblanet (brettsam) deleted the brettsam/fix-channel-shutdown-race branch July 10, 2026 16:07
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.

5 participants