-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Make HttpWebRequest.GetRequestStream return same instance (fixes #41403) #116757
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
Make HttpWebRequest.GetRequestStream return same instance (fixes #41403) #116757
Conversation
src/libraries/System.Net.Requests/src/System/Net/HttpWebRequest.cs
Outdated
Show resolved
Hide resolved
…beginning of InternalGetRequestStream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, thanks for the contribution! This seems mostly ok, however we need to add async path test + fix up the async path, to have the same behavior with sync path.
CI Failures look unrelated, I re-triggered it.
I've run the same test but async and it seems to be ok. Doesn't that mean the async path will have same behavior? |
This is what I get when I convert the test to async, for the context: |
I've double checked. I had stashed changes that are fixing that error. My bad. |
…equestStream_ReturnsSameInstanceWithoutLoopback_Async test
src/libraries/System.Net.Requests/src/System/Net/HttpWebRequest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Requests/src/System/Net/HttpWebRequest.cs
Outdated
Show resolved
Hide resolved
@@ -1146,6 +1152,8 @@ public override IAsyncResult BeginGetRequestStream(AsyncCallback? callback, obje | |||
throw new InvalidOperationException(SR.net_repcall); | |||
} | |||
|
|||
Interlocked.Exchange(ref _endGetRequestStreamCalled, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liveans, why is the code tracking whether begin/end were called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the code tracking whether begin/end were called?
I'm not sure about the historical reason, but code was in that way since I've started to work on it. So, I didn't try to break the existing functionality.
My guess is that: It was due to APM functionality, and there are tests for it in the test suite as well.
But since people should be using Task-based functions instead, I think we should be safe to delete them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it means that these 4 fields should be safe to delete?
private bool _beginGetRequestStreamCalled;
private bool _beginGetResponseCalled;
private bool _endGetRequestStreamCalled;
private bool _endGetResponseCalled;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, we can, but I'd rather prefer to keep it as-is right now. We might consider removing it later. I'll file an issue for it.
/azp run runtime-libraries-coreclr outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
Thanks for the contribution @Lukeuke, can you accept the CLA as described in the second comment? So, we can merge it. |
@dotnet-policy-service agree |
Accepted! Thanks for the opportunity to contribute and your time. It was new experience to me. I hope that it won't be the last. |
Summary
Fixes a compatibility issue where
HttpWebRequest.GetRequestStream()
returned a new stream instance on each call, unlike .NET Framework which returns the same instance.Changes
_requestStream
insideInternalGetRequestStream
GetRequestStream_ReturnsSameInstanceWithoutLoopback
.Fixes: #41403