Avoid disposing invalid handle in HttpSys server close#65378
Merged
wtgodbe merged 1 commit intorelease/10.0from Feb 18, 2026
Merged
Avoid disposing invalid handle in HttpSys server close#65378wtgodbe merged 1 commit intorelease/10.0from
wtgodbe merged 1 commit intorelease/10.0from
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression in the HttpSys server shutdown path by preventing a double-close of the request queue handle after switching to HttpCloseRequestQueue, aligning handle lifecycle management with Http.Sys API requirements.
Changes:
- Keep
HttpCloseRequestQueue(Handle)as the authoritative close operation for the request queue. - Prevent a subsequent
SafeHandle.Dispose()from attempting to close the same native handle by marking the handle invalid after closing. - Add clarifying comments about disposal order relative to
ThreadPoolBoundHandle.
|
|
||
| BoundHandle.Dispose(); | ||
| Handle.Dispose(); | ||
| Handle.SetHandleAsInvalid(); |
There was a problem hiding this comment.
After Handle.SetHandleAsInvalid(), consider still calling Handle.Dispose() to suppress the SafeHandle finalizer and release managed resources; disposal should be a no-op for the native handle once it’s marked invalid.
Suggested change
| Handle.SetHandleAsInvalid(); | |
| Handle.SetHandleAsInvalid(); | |
| Handle.Dispose(); |
halter73
approved these changes
Feb 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Avoid disposing invalid handle in HttpSys server close
Description
HttpSys docs say we should close the request queue with
HttpCloseRequestQueueand not withCloseHandle. So the PR #61325 noticed this while making an unrelated change and updated the code to callHttpCloseRequestQueue. Unfortunately, we kept the oldHandle.Dispose()code which is effectively a double free.The fix is to mark the handle as invalid after closing the request queue so we avoid the double free.
Fixes #65259
Customer Impact
Error log (and exception from
Dispose) when cleaning up HttpSys server.Issue: #65259
Regression?
Regressed in #61325 (10.0-p5)
Risk
Customer reported exception was easy to repro and thus easy to verify it was fixed with the change.
Verification
Packaging changes reviewed?