Skip to content

Conversation

brettsam
Copy link
Member

@brettsam brettsam commented Aug 25, 2025

Fixes #11263

The bug here is that during a request, we register a DI child scope container with the request... then we dispose it mid-request, so when anything in ASP.NET tries to get a service later, it throws. It's a race b/c it's possible that the request returns before the old container is disposed. Despite this, everything seems to be working b/c all the hard work has already been done by the time the exception is thrown. The JobHost is restarted and everything continues on happily even though we return a 500 to the caller.

I have a preliminary PR that I've just pushed up but it's not truly complete. It'll work for what we need but it's quite tricky to get right with how DI works.

Some background:

What I've got should be good enough for the very specific scenario we need it for, but there still seems like there's gaps that may bite us later.

Want to discuss with @fabiocav later whether we should use this same approach? Or abandon it and just skip registering services for /admin calls? Or if there's other approaches.

Will leave it in Draft for now.

Edit:
This is now ready for review. Rather than use the non-optimal approach with the built-in DI, we're going to just skip replacing these services on calls that we know don't need them and can be problematic. We can add to this if we need to in the future.

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)

@brettsam
Copy link
Member Author

Added a bunch more context to the description; leaving this in Draft now until I can discuss with @fabiocav. It's possible this was a purposeful omission and he had another plan (or maybe not :-))

@brettsam brettsam force-pushed the brettsam/resume_fix branch from 76e746f to 66d0b08 Compare October 7, 2025 20:03
@brettsam brettsam marked this pull request as ready for review October 7, 2025 20:03
@brettsam brettsam requested a review from a team as a code owner October 7, 2025 20:03
@Copilot Copilot AI review requested due to automatic review settings October 7, 2025 20:03
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 fixes an ObjectDisposedException that occurs when calling the /admin/host/resume endpoint by preventing the registration of a DI child scope container for this specific request type.

Key changes:

  • Adds detection for admin resume requests to avoid DI container disposal issues
  • Updates tests to use sequential job host restart configuration and adds error logging validation
  • Implements conditional middleware registration to skip problematic DI scope handling for resume requests

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
HttpRequestExtensions.cs Adds IsAdminResumeRequest() method to detect resume endpoint requests
WebJobsApplicationBuilderExtension.cs Conditionally registers ScriptHostRequestServiceProviderMiddleware to skip resume requests
DrainModeResumeEndToEndTests.cs Adds error logging validation and configures sequential job host restart for testing

@brettsam
Copy link
Member Author

brettsam commented Oct 7, 2025

Updated approach after talking with @fabiocav -- we'll just skip the service replacement on /admin/host/resume calls

@brettsam brettsam merged commit b851987 into dev Oct 7, 2025
9 checks passed
@brettsam brettsam deleted the brettsam/resume_fix branch October 7, 2025 21:05
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.

/admin/host/resume throws ObjectDisposedException
3 participants