Repository navigation
HttpListener.Stop closes the request queue handle with CloseIoEx method - #684
Merged
alnikola merged 8 commits intoDec 12, 2019
Merged
Conversation
davidsh
reviewed
Dec 9, 2019
davidsh
reviewed
Dec 9, 2019
davidsh
reviewed
Dec 9, 2019
Contributor
Author
|
/azp run libraries-outerloop |
|
No pipelines are associated with this pull request. |
Contributor
Author
|
/azp run runtime-libraries outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
davidsh
reviewed
Dec 9, 2019
scalablecory
reviewed
Dec 9, 2019
Code style fixes
Contributor
Author
|
/azp run runtime-libraries outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
davidsh
reviewed
Dec 10, 2019
davidsh
reviewed
Dec 10, 2019
Contributor
Author
|
/azp run runtime-libraries outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
Author
|
/azp run runtime-libraries outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
davidsh
approved these changes
Dec 11, 2019
Contributor
Author
|
/azp run runtime-libraries innerloop |
|
No pipelines are associated with this pull request. |
Contributor
Author
|
/azp run runtime-libraries |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
Author
|
/azp run runtime-libraries outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Currently, if HttpListener.Stop is called while the other thread is blocked inside a synchronous GetContext cal, it has no effect because Stop cannot dispose the request queue handle. This is caused by a reference counting mechanism implemented in SafeHandle which prevents disposal of the native handle due to the following reason.
GetContext method invokes the native HttpReceiveHttpRequest to start listening for incoming requests. HttpReceiveHttpRequest is called through P/Invoke and accepts SafeHandle as a request queue handle. In such case, runtime injects a special call to SafeHandle.DangerousAddRef incrementing the ref counter to prevent an accidental disposal from the managed side. In general, it's a good safety measure, but in the given scenario it prevents SafeHandle.Dispose from actually closing the underlying OS handle thus GetContext gets blocked until a next request arrives.
To overcome this limitation, PR adds call to CloseIoEx before invoking Dispose to close the request queue and unblock GetContext.