Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WinHttpHandler] Move _cachedSendPinnedBuffer ownership to WinHttpRequestState #101725

Merged
merged 4 commits into from
May 8, 2024

Conversation

antonfirsov
Copy link
Member

@antonfirsov antonfirsov commented Apr 30, 2024

A race between WinHttpRequestStream.WriteAsync and WinHttpRequestStream.Dispose can lead to Dispose unpinning the buffer forwarded to WinHttp, which can potentially lead to AccessViolationException:

Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset),

This has been fixed in dotnet/corefx#6500 for WinHttpResponseStream, this PR is applying the same fix for WinHttpRequestStream.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

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

LGTM.

To answer https://github.com/dotnet/corefx/pull/6500/files#diff-8db7e154523836be1aa177c05ae0decb22c602791eabf11d01823c80ac9927d8R131
It seems like the WriteAsync has also similar logic to ReadAsync, right?

@antonfirsov
Copy link
Member Author

It seems like the WriteAsync has also similar logic to ReadAsync, right?

Yes:

if (_state.TcsInternalWriteDataToRequestStream != null &&
!_state.TcsInternalWriteDataToRequestStream.Task.IsCompleted)
{
throw new InvalidOperationException(SR.net_http_no_concurrent_io_allowed);
}

Note that the logic is prone to races in both streams, but that's beyond this PR.

@karelz karelz added this to the 9.0.0 milestone Apr 30, 2024

This comment was marked as outdated.

@antonfirsov
Copy link
Member Author

There are possibly related outerloop failures, this needs investigation.

@antonfirsov antonfirsov added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label May 1, 2024

This comment was marked as outdated.

This comment was marked as outdated.

@antonfirsov
Copy link
Member Author

antonfirsov commented May 7, 2024

After a second look and more testing, the failures look unrelated:

I will do a couple of further outerloop reruns before merging this.

@antonfirsov
Copy link
Member Author

/azp run runtime-libraries-coreclr outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@antonfirsov antonfirsov removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label May 8, 2024
@antonfirsov
Copy link
Member Author

All test failures are unrelated, merging.

@antonfirsov antonfirsov merged commit a7702f4 into dotnet:main May 8, 2024
81 of 91 checks passed
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
…#101725)

Fixes a race between `WinHttpRequestStream.WriteAsync` and `WinHttpRequestStream.Dispose` that can lead to AV.
@antonfirsov
Copy link
Member Author

/backport to release/8.0-staging

Copy link
Contributor

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/9034004390

Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
…#101725)

Fixes a race between `WinHttpRequestStream.WriteAsync` and `WinHttpRequestStream.Dispose` that can lead to AV.
@github-actions github-actions bot locked and limited conversation to collaborators Jun 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants