It turns out that setting the WinHTTP 'Connect' timeout does nothing. We discovered this because we still got ERROR_WINHTTP_TIMEOUT errors after about 20 seconds even after setting the 'Connect' timeout to INFINITE. We discussed this with the WinHTTP team and they told us that this timeout is essentially deprecated due to performance enhancements in the TCP stack.
For the technically curious, here is the explanation. Underneath the 'Connect' timeout is really a set of TCP timeouts related to setting up the socket via the 3-leg SYN/ACK exchange. The TCP timeout is about retransmits with backoff and how many is tried by the winsock stack. The default of these initial packet exchanges is 21 seconds with 2 retransmits (3 overall SYNs) and initial RTO of 3 (3 + 6 + 12). So that explained the timeouts we saw during periods of high network congestion.
There is no API exposed in WinHTTP to control those low-level TCP timeouts. And thus it doesn't make any sense to have a 'ConnectTimeout' on the WinHttpHandler class.
Commit migrated from https://github.com/dotnet/corefx/commit/ee0b3a76c8c57ef80d1d53a16deb5b0bc6b46793
I'd added this when bringing properties from WinHttpHandler to CurlHandler in bulk, with the expectation that we might expose them. Since we're not planning on exposing this particular property from HttpClientHandler (turns out it's not very useful in practice), I'm removing it.
Commit migrated from https://github.com/dotnet/corefx/commit/953bbe0006ce7f29c87b798eb10d072df06d6f99
Building on the current use of environment variables for passing in test settings, added a common test helper class to allow the http and websocket tests to access alternate test servers. This will help with load balancing and network latency issues which are causing occasional timeouts in CI tests. This will also allow developers to run their own version of the Azure test endpoints. Consolidated the current environment variables used and standardized on a naming format.
Fixesdotnet/corefx#2383.
Commit migrated from https://github.com/dotnet/corefx/commit/3603ed2578220f0ecb2f101324e04acb80fa3196
On Unix when an HttpClientHandler is disposed, we cancel all outstanding operations associated with that handler. It turns out this isn't the desired behavior (aka the behavior of WinHttpHandler), which is that we should cancel all outstanding operations that haven't yet published its HttpResponseMessage, but for requests where the HttpResponseMessage has been published, it should remain valid.
This commit tweaks the behavior accordingly and adds a test for it.
Commit migrated from https://github.com/dotnet/corefx/commit/f949d92b3ee26168277f56fbd2c6686505ea0b4a
One of the HttpClient client tests hangs on a machine with a single core.
xunit by default uses a SynchronizationContext that has N threads to do
work, where N defaults to Environment.ProcessorCount. Thus on a single
core machine, there's only one thread available to run tests, and if that
thread blocks waiting for an async operation that'll schedule work back to
that context, it'll deadlock.
Commit migrated from https://github.com/dotnet/corefx/commit/916798757c122b81e61666c4f0af0c446d378824
* Improve WinHttpHandler logic regarding default credentials
In some cases, WinHttpHandler was not sending default credentials that were specified inside a custom ICredentials object. In other cases, default credentials would be sent even though CredentialCache.DefaultCredentials was not specified. The code was incorrectly comparing the proxy and server credential (ICredential interface) values against the DefaultCredentials object. Instead, the ICredentials.GetCredential() method should be called to compute the final NetworkCredential object. This takes into account the given uri and auth scheme.
This PR fixes the logic by delay the setting in WinHTTP for releasing default credentials. This ensures that default crdentials are released when requested.
Fixesdotnet/corefx#8176.
* Address PR feedback
Reword comments for clarity.
Add TODO issue.
Sending default creds to proxy only needs MEDIUM security policy.
Commit migrated from https://github.com/dotnet/corefx/commit/90b8ff36c8c9f9cfb1a2cf1302ff7a98ac7801ed
libcurl v7.37 added support for parsing IPv6 uris with scope/zone IDs, but some of the Unix systems we target have an older libcurl. Rather than just saying "use a newer libcurl", we can use libcurl's CURLOPT_ADDRESS_SCOPE to explicitly set the link-local scope ID when it's set, and allow such Uris to be used on older libcurls.
Commit migrated from https://github.com/dotnet/corefx/commit/0c9948a86d36963d92f7e53c8df18c150675c9b5
We currently make a lot of calls off-box in our unit tests. By adding SSL support to the loopback server, we should be able to convert many more tests to avoid needing to actually hit the network. This adds such basic support, and converts a few tests to use it.
Also, since I was moving the certificate configuration code to a central location, I fixed an issue related to cleanup.
Commit migrated from https://github.com/dotnet/corefx/commit/b90795e1d5d7e8d8c68b9ca23d53b1ba0e392f46
* Fix bug in Cookie where Value can == null
* Add a regression test for the bug
* Fix compilation errors
* Fix the netcore50 version of Cookie as well
* Update CookieTest.cs
* Add comment about the test failing on desktop
Commit migrated from https://github.com/dotnet/corefx/commit/9872c2aa881e8651486a6e3ae90fb2f59038baf6
These tests require the client and server to be on a Windows Active Directory domain. These tests are Windows specific. Currently this cannot be done in the CI system. So, these tests are only enabled when an environment variable is set which points to the test server.
There is a separate todo item dotnet/corefx#4989 to provide more automated scripts for setting up the test server. For now, there is a readme file with some details.
These tests will help support fixes for dotnet/corefx#8176 and related bugs.
Commit migrated from https://github.com/dotnet/corefx/commit/4739da8c8d4965fdaf2fc45ae915297208672d15
HttpContentAsyncStream is used by CurlHandler as the request content stream, with writes to it done via HttpContent.CopyToAsync. We expect the writes to all be asynchronous via WriteAsync. However, it's possible for an override of CopyToAsync to use Write, and if it does, and if we just delegated from Write(...) to WriteAsync(...).GetAwaiter().GetResult(), we would likely deadlock, as the CopyToAsync call is invoked from the single thread responsible for processing libcurl interactions, including supplying the reader that would unblock the writer. To handle this, we have two options: schedule the CopyToAsync to be invoked asynchronously just in case it does a synchronous write, or implement the write to buffer the data.
The former is what was done in https://github.com/dotnet/corefx/pull/4095. It adds some cost to the expected / common case, but more importantly and worse it can also lead to concurrency problems and spurious exceptions, as for example if the request is faulted/canceled between the time that a task to invoke CopyToAsync is scheduled and the time that it actually executes, we could be invoking CopyToAsync on a disposed HttpContent; worse, we could
end up invoking CopyToAsync while it's being disposed, which could lead to arbitrary state corruption, and which means we can't guard against this with checks to see if the task has already completed. The only way to fully guard against that is via a lock, but such a lock would itself lead to deadlocks, as the reader that would unblock the writer would have to take the same lock.
In comparison, buffering has the downside of taking up more and arbitrary amounts of memory to store all of the input. But, we expect synchronous Writes to be rare, and code shouldn't be doing it anyway; if it does, the fix should really be to switch to asynchronous writes. This commit changes from the first approach to the second, using buffering in synchronous Write calls in order to ensure correctness and to optimize for the expected case.
Commit migrated from https://github.com/dotnet/corefx/commit/1ac3f5e62a0d094e7e4277afc43cb1e0c6260b83
The current tests validating HTTP request message version were depending on a server behavior that is not guaranteed. In particular, HTTP RFC 7230 states that servers are NOT required to respond back with the same minor version if they support a higher minor version. In fact, the RFC states that servers SHOULD send back the highest minor version they support. So, testing the response version to see if the client sent a particular request version only works for some servers. In particular the 'Http2Servers' used in these tests seemed to echo the minor version of the request.
However, depending on network configuration, intermediate proxies can change the HTTP version that ends up getting sent to the destination server. And as a result, we can have unpredictable behavior in these tests.
To fix this, the tests were switched to use a loopback server that has deterministic behavior.
Commit migrated from https://github.com/dotnet/corefx/commit/d1ffcbcc120d3797dadce6196f499a0631e47caf
- The GetAsync_ResponseWithSetCookieHeaders_AllCookiesRead test has been failing with some regularity in CI, with strange GatewayTimeout errors. I don't know why this particular test is so much more susceptible to that, but I've changed the test to use a local loopback server rather than an external site.
- The SendAsync_ReadFromSlowStreamingServer_PartialDataReturned test was relying on timings from the server that might not always be correct, and due to internal differences between curl and WinHttp were very frequently wrong on Unix such that the test was disabled there. I reimplemented it with a local loopback server, too.
- I've added another mini-stress test, with posts instead of gets.
Commit migrated from https://github.com/dotnet/corefx/commit/9b6a0224c3e404afe3f2c58dfb59e2068391c879
We've standardized on using Unix in most cases where we only cross-
compile once for Unix. This change cleans up mentions of Linux/OSX when
we aren't actually cross-compiling for those OSes.
The remaining projects that still cross-compile for Linux/OSX are:
System.Diagnostics.Process
System.IO.FileSystem.Watcher
System.Net.NetworkInformation
The System.Net.Security functional tests seem to still have a distinct
difference in functional behavior on OSX so I have also left these
configured to cross-compile for Linux/OSX.
Commit migrated from https://github.com/dotnet/corefx/commit/16ee317fa4e194ff7cf61e923caf103909e391f1
Packages that support desktop need to install in projects that use
packages.config, so we should not rely on RID-specific assets for
desktop assets. Additionally, if some decides to use project.json and a
RID we need to make sure they still get the right desktop asset.
This change standardizes most of the desktop builds to specify both RID
and TFM. The common packaging targets will put the asset in both
lib/TFM and runtimes/RID/lib/TFM for desktop projects.
Commit migrated from https://github.com/dotnet/corefx/commit/0b7a2b6b4d1cf5f5a1fc2abc7e8c00c298bbe449