This is a large PR and addresses work item dotnet/corefx#3000. I apologize for not being able to structure it in a series of smaller commits.
The bulk of this PR is switching WinHttpHandler to use the async pattern of calling WinHTTP APIs. This involved a significant restructuring of the code. As part of that, I split up the large WinHttpHandler class into multiple, smaller, helper classes.
While the intent of using async WinHTTP calls is better performance and cancel-ability, this PR has not been fully optimized yet. Due to the schedule of RC1 code complete next week, it's important that this PR get in and get mileage on it in the next few weeks.
There are several TODO items that will be done in later PR's. There is still work being tracked in dotnet/corefx#2165 for various follow-up items. For example, re-conciling the best SafeHandle pattern to use for WinHTTP between WebSockets.Client and WinHttpHandler.
I'm currently using a simple Debug.WriteLine for verbose debug logging which can be turned on/off via environment variable. I plan to switch this to System.Net ETW trace loggers in the next commit and/or PR. But the logging has proved very useful in diagnosing issues.
Please provide feedback. Depending on the feedback, some of it will be marked as follow-up items for future PRs.
Commit migrated from https://github.com/dotnet/corefx/commit/d8e5371a5d0f9f4bb3aa85127cb78adf89dde1fb
This PR mainly addresses "handle leaks" dotnet/corefx#2963, dotnet/corefx#2762, dotnet/corefx#2793. In investigating the leaks, I discovered that our use of the SafeHandle pattern was not quite right. Native Windows WinHTTP handles wrapped by SafeHandle need additional lifetime management protection to preserve parent-child relationships. Closing the parent handle too early will invalidate the child handle. So, added a SetParentHandle() method to SafeWinHttpHandle to protect against this. This also simplified the passing of handles to the WinHttpResponseStream class.
After adding leak detection, I discovered a race condition caused by an CancellationToken.Register that should not exist in WinHttpHandler.
This inadvertently provided a way for the awaited SendAsync() task to return back to the caller even though the StartRequest() method is still
running.
Added unit tests to validate the behavior assumptions and to track leaks in the WinHttpHandler logic.
This change does not affect the SafeWinHttpHandleWithCallback class that is used by System.Net.WebSocket.Client. But that class is incorrectly using the SafeHandle pattern w.r.t. Dispose() and I will be fixing that in a later PR.
Commit migrated from https://github.com/dotnet/corefx/commit/a75ec027daa53114c788464878e2947ae7d5a65e
This change sets up the layout for having multiple test projects for
WinHttpHandler. It follows the current guidlines as well as working
within the BUILDTOOLS requirements of having ".Tests.csproj" for the
names of the projects.
Also, fixed up some cross-platform definitions in the solutions files
for Http and WinHttpHandler.
After this PR is done, we will be migrating a large set of http
functional tests to GitHub
Commit migrated from https://github.com/dotnet/corefx/commit/42d81c41175ab8832032a2a387b8dc58365604a9