Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Release pinned buffers correctly for WinHttpHandler, WinHttpWebSocket #6500

Merged
merged 1 commit into from
Feb 29, 2016
Merged

Release pinned buffers correctly for WinHttpHandler, WinHttpWebSocket #6500

merged 1 commit into from
Feb 29, 2016

Conversation

davidsh
Copy link
Contributor

@davidsh davidsh commented Feb 28, 2016

Both WinHttpHandler and WinHttpWebSocket use pinned buffers for receiving and sending data. The pinned GCHandle was being freed during the dispose of the WinHttpHandler or WinHttpWebSocket objects. The problem is that the buffer should not be unpinned until the async operation is done. It's possible for any async operation to be in flight (and where native code uses the buffer) when the object is explicitly or implicitly disposed.

This fix moves the ownership of the pinned GCHandle to their respective state objects (WinHttRequestState, WinHttpWebSocketState). These objects are strongly rooted and are not released until all async operations are completed and the WinHTTP handles are fully closed. That makes these state objects a safe place to own and free the pinned buffers.

Fixes #2508 and #6142

Both WinHttpHandler and WinHttpWebSocket use pinned buffers for receiving and sending data. The pinned GCHandle was being freed during the dispose of the WinHttpHandler or WinHttpWebSocket objects. The problem is that the buffer should not be unpinned until the async operation is done. It's possible for any async operation to be in flight (and where native code uses the buffer) when the object is explicitly or implicitly disposed.

This fix moves the ownership of the pinned GCHandle to their respective state objects (WinHttRequestState, WinHttpWebSocketState). These objects are strongly rooted and are not released until all async operations are completed and the WinHTTP handles are fully closed. That makes these state objects a safe place to own and free the pinned buffers.

Fixes #2508 and #6142
@davidsh davidsh added area-System.Net blocking Marks issues that we want to fast track in order to unblock other important work labels Feb 28, 2016
@davidsh davidsh added this to the 1.0.0-rtm milestone Feb 28, 2016
@davidsh
Copy link
Contributor Author

davidsh commented Feb 28, 2016

@stephentoub @CIPop PTAL

@@ -147,7 +163,17 @@ private void Dispose(bool disposing)

if (_operationHandle.IsAllocated)
{
// This method only gets called when the WinHTTP request handle is fully closed and thus all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything we can assert to ensure that?

@stephentoub
Copy link
Member

LGTM

davidsh added a commit that referenced this pull request Feb 29, 2016
Release pinned buffers correctly for WinHttpHandler, WinHttpWebSocket
@davidsh davidsh merged commit 378ce37 into dotnet:master Feb 29, 2016
@davidsh davidsh deleted the winhttpwebsocket_dispose branch February 29, 2016 00:41
@karelz karelz modified the milestones: 1.0.0-rtm, 1.2.0 Dec 3, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…ispose

Release pinned buffers correctly for WinHttpHandler, WinHttpWebSocket

Commit migrated from dotnet/corefx@378ce37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net blocking Marks issues that we want to fast track in order to unblock other important work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Release pinned buffers at correct time in WinHttpResponseStream, WinHttpWebSocket
6 participants