- We were using WriteAsciiStringAsync in one place we shouldn't have been. Change it to WriteStringAsync.
- We were potentially overflowing in a multiplication on MaxResponseHeadersLength if it was set to a very large value. Changed it to use long multiplication and to cap the max length at int.MaxValue.
- We were accidentally using DateTimeOffset.Now instead of UtcNow when getting the current time during stale pool removal. Change to UtcNow.
- We had an unnecessary/unreachable catch block. Remove it.
- In a race condition where the handler and thus its pool manager was disposed while the cleaning timer callback was in flight (either already queued or already running), we could potentially dispose of the timer and then the callback attempt to change the timer and incur an ObjectDisposedException that would go unhandled on a thread pool thread. One fix would be to track disposal under the same lock that's used to mutate the cleaning timer, but that incurs the cost of tracking disposal and taking a lock on disposal in order to deal with a rare race condition (that we've never actually seen happen). Instead, I opt to simply catch and eat any ODEs that occur.
- If either of the connection lifetime values are set at 0, we avoid putting connections back into a pool and thus also avoid creating the cleaning timer. But we're still putting the created pool into the pools collection, which in theory in an extreme case could be a leak. The fix is simply to not store the pool into the pools in this case.
Commit migrated from https://github.com/dotnet/corefx/commit/c998e559dc3682bda42bedd8379442f1e457d136
This PR will reduce the calls to WinHTTP GetProxyForUrl() if a previous call recently discovered
no PAC file within a certain timeframe. We call this API when "Automatically detect settings"
is turned on. The default configuration on Windows has this proxy setting always turned on. This
is ironic given that most network environments don't have a PAC file on the network. So, it's
important to try to optimize this common case on customers' networks.
Initial testing shows at least a 2x speed improvement with these changes.
I did not use any locking mechanisms since those would drag down performance. In the worst case,
any race condition would mean we might call GetProxyForUrl() an extra time. But since we're only
filtering on ERROR_WINHTTP_AUTODETECTION_FAILED, it is unlikely to actually change over time.
That particular error means that the WPAD protocol was able to complete on the network, but the
answer discovered is that there is no PAC file registered on the network.
Fixesdotnet/corefx#28543
Commit migrated from https://github.com/dotnet/corefx/commit/712d3065cef7f28eae96a578b8bd73870e9b2cd5
As part of looking at the usability of .NET Core network logging (compared to
.NET Framework), I did a walkthru of the current logging in SocketsHttpHandler.
I noticed some inconsistencies in how the NetEventSource logging is being used.
For the 2.1 release, I wanted to at least add more logging to some key areas
including places where we ignore errors/exceptions.
There is still more work to do to improve the logging to make it useful for
developers. This includes doing a better job at logging for System.Net.Sockets
as well as looking into other tool options besides PerfView to look at the traces.
I also fixed the sample script for using starting the traces using Windows logman.
The default log buffer size is too small even for for simple traces. Now, using PerfView
on all the System.Net.* traces no longer shows an error about traces being dropped.
Commit migrated from https://github.com/dotnet/corefx/commit/158ed4d059a875e6828c176ce7ecc4a221b331e3
* Update the System.Runtime and System.Memory ref based on new buildtools
* Fix HttpContent TryGetBuffer and update System.Runtime ref
* Update System.Memory ref and fix PipeAwaitable (assign CancellationTokenRegistration)
* Fix 'use of unassigned local' error in System.Memory performance tests
Commit migrated from https://github.com/dotnet/corefx/commit/bd1911e9b3bf104fd9821a4fc68ea1baafe780ef
Windows 7 and Windows 2008 R2 support TLS 1.1 and 1.2, but for legacy reasons by default those protocols are not enabled when a developer elects to use the system default. However, in .NET Core 2.0 and earlier, HttpClientHandler would enable them, due to being a wrapper for WinHTTP, which enabled them. Both for compatibility and because we prefer those higher protocols whenever possible, SocketsHttpHandler also pretends they're part of the default when running on Win7/2008R2.
Commit migrated from https://github.com/dotnet/corefx/commit/0c7a1de0448c9dee76723d0bedd90f76c3436662
I couldn't get it to fail locally, but I believe the issue was that sporadically WinHttpHandler would not reuse the original connection, in which case it would either not close the first and the test would hang because nothing was accepting the second connection, or it would close the first and fail because the server was expecting a second request on the connection. This fixes it by using Connection: close on the first response so that the client won't reuse the same connection.
Commit migrated from https://github.com/dotnet/corefx/commit/586cffcdfdf23ad6c193a4bf37fce88a1bf69508
* add bypass list processing
* remove 10.37.129.2
* update assembly references
* add bypass list processing
* remove 10.37.129.2
* update assembly references
* use Regex.Escape to escape . and [. Add more test cases.
* feedback from reviews
* fix some of the style comments. more changes to come.
* feedback from @stephentoub
* use UriHostNameType and IdnHost consistently to possibly avoid allocations. Add new test for various unexpected input
* replace String.Compare with string.Compare
Commit migrated from https://github.com/dotnet/corefx/commit/c9d1ec1764f421f35cfe0bbc71bf2f81bc8f0f8d
By default, .NET Core defaults to allowing TLSv1, TLSv1.1, and TLSv1.2. However, whereas .NET Framework allows a developer to opt-in to SSLv2/SSLv3, .NET Core currently blocks it. This means developers are unable to use .NET Core when they need to communicate with an endpoint they don't control and that's unfortunately limited to one of these protocols, which blocks adoption of .NET Core.
This commit stops blocking these protocols. They're still disabled by default, and compiling against them still results in a deprecation warning, but if a developer chooses to ignore the warning and explicitly sets SslProtocols, they are at least able to use the protocols, subject to whatever the underlying operating system allows (e.g. Windows stops supporting SSLv2 as of v1607).
Commit migrated from https://github.com/dotnet/corefx/commit/3cc6fda0c6abe76eea222c165ebdf816e83df564
* 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