* Update IRetainable, OwnedMemory, and MemoryHandle APIs
* Split OwnedMemory into MemoryManager and IMemoryOwner
* Update ReadOnlySequence, ArrayMemoryPool, and BufferSegment
* Update System.Memory and System.IO.Pipeline tests
* Temporarily skipping the failing Pipelines tests until impl is corrected.
* Update the reference assembly to match implementation and cleanup
* Update API compat baseline for UAPAOT and add GenFacadesIgnoreMissingTypes
* Fix the System.Runtime ref
* Add back the Pin methods to the uapaot api compat baseline
* Clone the API compat baseline from uapaot and add it for uap as well.
* Update BuildTools, CoreClr, CoreFx, CoreSetup, ProjectNTfs, ProjectNTfsTestILC to preview3-02630-01, preview3-26330-08, preview3-26330-06, preview3-26330-04, beta-26330-00, beta-26330-00, respectively
* Fix pipelines tests and update the api compat baseline shim for uapaot
* Add empty Unpin override to pipe pool test.
* Fix the System.Net.Http Functional tests
Commit migrated from https://github.com/dotnet/corefx/commit/f592e887e2349ed52af6a83070c42adb9d26408c
We're supposed to only use a ValueTask<int> once. But there's a race condition where we may not only use one more than once, we might do so concurrently, resulting in a variety of different exceptions depending on how the race condition manifests.
When we take a connection out of the connection pool, we want to check whether it's still valid for use. We could poll, but since the request/response is going to need to issue at least one read anyway, we just do so preemptively, then checking whether the read completed synchronously (if it did, we can't use the connection). This gets stored in a field on the HttpConnection that can later be read. However, we may also create the read ahead task in another situation, which is if we're unable to easily fish out the underlying socket used by the connection (as happens with tunneling), when the pool periodically scavenges and looks for dead connections, rather than polling it just issues that read even earlier. Doing so, however, means that we'll have kicked off tasks that are likely to complete with an exception if the connection is terminated in an unfriendly manner. To avoid such exceptions spamming TaskScheduler.UnobservedTaskException, we check this stored task when disposing the connection.
That, however, creates the race condition. If the connection is disposed (e.g. due to cancellation) at just the wrong time, the request/response may be in the process of working with that initial read just as the disposal goes to interact with that same read ahead task. Badness results.
The fix is to add a tiny amount of synchronization, such that just one call site can take ownership of the read ahead task.
Commit migrated from https://github.com/dotnet/corefx/commit/366496832fbf9c893a33ebed176d6e053c721ca1
* Change SocketsHttpHandler's 101 response stream to buffer response reads
The connection already has a buffer; use it.
* Reduce buffering in ManagedWebSocket.ReceiveAsync
Today we use a big-ish receive buffer, reading all data into the receive buffer and then copying from there into the caller-provided destination buffer. With this change, we assume that the underlying stream is providing the desired level of buffering, and thus only use a buffer small enough to handle message headers and control payloads (the latter for simplicity, as no caller-supplied buffer is available there).
* Change ClientWebSocket to avoid creating a large buffer
Commit migrated from https://github.com/dotnet/corefx/commit/06aa6f0ce4cdf78985f029f218007a7d55f8965f
Now that the authentication test failures have been diagnosed, re-enable most of the Digest authentication test cases on CurlHandler. Four additional cases had to be moved to the SocketsHttpHandler only tests, since they fail on CurlHandler and do not have fixes yet.
The digest test cases have to use credentials without a domain when run against CurlHandler. This is because Curl does not allow us to set the realm parameter used to send the domain along with a digest authorization header.
Commit migrated from https://github.com/dotnet/corefx/commit/0257e6cc85c3a0421cb99a473fa187a43eb46b6a
Adds a small test to visit a list of sites using SocketsHttpHandler and allow easy debugging and comparison with platform handlers in case one needs to investigate. The tests are disabled by default and are controlled by Xunit traits.
Commit migrated from https://github.com/dotnet/corefx/commit/8e18a0e0453654ed88c3729ffad580dff984601a
* refactor some proxy tests using new loppback server and new auth function
* feedback from reviews
* correct split() use. My local build did not fail for what ever reason
* disable ProxyExplicitlyProvided_DefaultCredentials_Ignored as it used to be
* refactor some proxy tests using new loppback server and new auth function
* feedback from reviews
* disable ProxyExplicitlyProvided_DefaultCredentials_Ignored as it used to be
* add test case for dotnet/corefx#27870
* skip new test on WindowNano
* add limit on Split() so it always splits to two tokens to avoid problems with : in the value
* update Split() as it seems not all c# flavors has the righ overload
* small improvement on header split
* feedback from review
Commit migrated from https://github.com/dotnet/corefx/commit/b2a119950cb52dd744f84b552de1da2df07b937b
This PR addresses some error handling problems in WinHttpHandler as well as
improves the error messages generated for WinHttpException.
This was root caused to a bug in WinHttp where it can't do a GET request with a
request body using chunked encoding. However, this exception was masked due to
an error handling bug caused by an inconsistency in how WinHttp associates
context values for callbacks during the WinHttpSendRequest API call. This PR now
fixes the error handling around synchronous errors being returned from
WinHttpSendRequest. The root WinHttp bug itself can't be fixed. So, doing a GET request
will still throw an exception, but it will be a catchable HttpRequestException.
Another bug was discovered while investigating dotnet/corefx#26278. WinHttpCloseHandle should only be
called once and should never race between threads. This is normally protected when
the request handle is closed via SafeHandle Dispose(). But there was a place in the
callback method where we called WinHttpCloseHandle directly against the raw handle.
Finally, the error messages for WinHttpExceptions have been improved to show the
error number and the probable WinHttp API call that generated the error. This will
save diagnostic time.
I also moved the WinHttpException source code back from Common. It was originally shared
between WinHttpHandler and ClientWebSocket. But then ClientWebSocket moved away from
WinHttp implementation. So, it makes more sense for this class to be under WinHttpHandler.
Example:
Original WinHttpException message: "The parameter is incorrect"
New WinHttpException message: "Error 87 calling WinHttpSendRequest, 'The parameter is incorrect'."
Closesdotnet/corefx#28156
Contributes to dotnet/corefx#26278
Commit migrated from https://github.com/dotnet/corefx/commit/ce4ebdfbf2080a38855ab8df5c9bb553db8724af
If cancellation is requested between the earlier check in the method and the call to Register, Register will return a default registration, and then the callback will end up seeing a default token rather than the original token. That will not only trigger the assert we've been seeing, but will also result in the wrong token being stored into the task.
Commit migrated from https://github.com/dotnet/corefx/commit/fb1177a42224b5882b2b2266ae516b444a0f30aa
The PreAuthenticate_FirstRequestNoHeader_SecondRequestVariousStatusCodes_ThirdRequestPreauthenticates tests a bunch of status codes, some of which are sporadically failing in CI with WinHttpHandler. According to the RFC, several of these status codes require that there not be a response body, but the test is sending one, and it would seem there are then race conditions that are causing WinHttp to fail here and there for these status codes, e.g. 204 and 304. This just fixes the test to not send a body.
Commit migrated from https://github.com/dotnet/corefx/commit/ca07fd9545336610e9768d76261c64c67f244721
When choosing what authentication scheme to use, WinHttpHandler picks the most secure scheme supported by the server. When the client does not support this scheme it closes the connection. This fix updates the authentication logic to instead pick the most secure scheme offered by the server that is also supported by the client.
This change also adds a test of the relevant behavior.
Fixes: dotnet/corefx#27672
Commit migrated from https://github.com/dotnet/corefx/commit/6d031a04f3df8fadd5b82d9c23d904182eea94e4
Currently when a connection is put back into the pool, we issue a pre-emptive read on the stream, as a way of being able to cheaply detect whether the stream has been closed. But this ends up incurring exceptions when the connection is then disposed of. We change to a model where we poll while the connection is in the pool, but issue a read while taking it out of the pool; we use this read as the first of the response and instead of doing another poll syscall when taking out the connection.
Commit migrated from https://github.com/dotnet/corefx/commit/6aea829f712618d589b6e61b551bd1c429fa97d8
* Use named arguments for more bool arguments
* Dispose of new HttpConnectionPool if we lose race condition
If two threads are racing to create the first connection for a specific pool, one of them will end up creating a pool object that's then discarded. Make sure we dispose it. Right now it doesn't really matter as there aren't any resources in an empty pool that need to be cleaned up, but it's a good measure and will help in the future if that changes.
* Fix SocketsHttpHandler.PreAuthenticate behavior
Previously SocketsHttpHandler.PreAuthenticate was causing SocketsHttpHandler to always add a basic auth header on every request if a basic credential could be retrieved from the supplied credentials. This is not how PreAuthenticate is supposed to work. Rather, the handler is supposed to track credentials that have previously been used to successfully authenticate, and then on subsequent requests use credentials from that successfully-authenticated cache.
* Add more tests
Commit migrated from https://github.com/dotnet/corefx/commit/e2ed932d985badf1551affc868f965d2f774bf4d
If HttpClient has a non-infinite timeout set, and/or if a cancelable token is passed in, it creates a token source linked to the pending requests token source and the passed in token, and passes that token into base.SendAsync, which in turn just delegates to the wrapped handler's SendAsync. If that wrapped handler throws an exception synchronously that propagates out of SendAsync, we never end up disposing of the linked token, which will end up leaving a reference to it in both the pending requests token source and the provided token's source.
Commit migrated from https://github.com/dotnet/corefx/commit/f7b7c502797662944ddce6f2542e92a2ad04250c
When SocketsHttpHandler puts a connection back into the pool, it issues a pre-emptive asynchronous read on the transport stream. This enables us to check whether any unexpected data has arrived on the connection, whether the connection has been closed, etc., and without polling (which could be done with a NetworkStream but not well with an SslStream). However, when we dispose of a connection from the pool, this task will potentially end up getting faulted, and while it won't crash the application by default, it will end up invoking the TaskScheduler.UnobservedException event.
This commit address this by ensuring that we always observe any exceptions that come from the read ahead task when the connection is disposed of (in the rare case where an HttpConnection is instead left for finalization, the event may still be raised, which is arguably a good thing, as the developer should be disposing responses.)
(The alternative would be to stop using the read ahead, and instead poll every time we wanted to know if the connection was still valid. That would mean storing the socket in addition to the stream on the connection, and would mean we might miss some errant data that was already pulled from the socket into an SslStream. It would also mean at least one more syscall for each request, as we'd check whether a connection from the pool was valid. For now I'm sticking with the read ahead.)
Commit migrated from https://github.com/dotnet/corefx/commit/850c1d76e7c5371c5a6e015afa7f25da32f9cdaa
The UseCallback_BadCertificate_ExpectedPolicyErrors tests had been
disabled when running against SocketsHttpHandler. The reason in the
comments was that the tests were not returning the proper
SslPolicyErrors.
These particular tests use external third party servers (*.badssl.com).
Running these tests now against the latest code shows no errors. It's
possible this was a problem related to those external servers. Renabling
the tests for now.
Fixesdotnet/corefx#23137
Commit migrated from https://github.com/dotnet/corefx/commit/a51680e39a871cbdf3f63bbd28adb3d1abe435f5