This test sends some of the data planned by Content-Length but keeps the connection open; the client is then supposed to read that data and verifies that it got only what was sent and didn't hang. But it's hanging on netfx. The problem is that ConnectStream.BeginRead on netfx first reads what it has buffered, and if it doesn't have buffered as much as was asked for, it then issues an asynchronous read rather than just returning the what it has.
Commit migrated from https://github.com/dotnet/corefx/commit/2f19b380923cfeb8a7387d6c9cfad30a0b713f38
Versions before 7.30 don't have this option. Previously we would throw a PlatformNotSupportedException. As devs would generally use an option of this type to increase the limit (since historically such a limit was 2 or 10 in the .NET Framework) rather than decrease it, and since it's already effectively infinite by default in .NET Core, with this commit, now we just ignore it. This helps to avoid PNSEs on the few platforms that still ship with too old a version of libcurl.
Commit migrated from https://github.com/dotnet/corefx/commit/113a7d5c47c5c0ab2aa8d7d39acf34a4e1618b24
To help diagnose pernicious exceptions, this debug-build-only change augments exceptions created using CreateExceptionUsingError to include the calling thread's stack trace, so that when these exceptions are then moved to other threads and propagated there, we can better correlate where they came from.
Commit migrated from https://github.com/dotnet/corefx/commit/2c368e81d9d07f0d40edf36047e5b93e44db200b
HttpClient on Unix fails for some sites, in cases where the site sends a response before it’s fully received the entirety of the request. That’s because HttpClient has logic to Dispose of the request content once the Task returned from the handler’s SendAsync completes, and unlike WinHTTP, libcurl doesn’t require that the whole request be sent before any of the response is processed. That means that CurlHandler may receive the response (or the response headers), complete the SendAsync task, but still be reading from the request content, which may then be disposed of by HttpClient while it’s still in use, causing potential corruption, exceptions, etc.
The Dispose behavior has other problems with it. A more generalized version of the above is that it prevents handlers that want to support full duplex communication, since it essentially requires that the whole request be sent before the response is processed. It also forces extra cost onto consuming code in some situations, as it means that the request content objects can’t be pooled and reused (since disposal typically invalidates objects for such a purpose, though in some cases a custom content could be developed to override and ignore Dispose).
A variety of approaches were explored to address this:
- Change CurlHandler to only complete the SendAsync Task when both the request has been fully sent and the appropriate portion of the response has been received. This is problematic, though, as with the pull model employed by libcurl, we don’t know reliably when the request has been fully sent.
- Change the disposal to be handled by the handlers rather than by HttpClient. This could help in that a handler like CurlHandler could simply defer disposal until libcurl tells it the “easy” operation is done. But it has other downsides. Today code can use an HttpClientHandler without HttpClient, e.g. by using HttpMessageInvoker instead of HttpClient, in which case it bypasses this disposal logic (and other logic provided by the relatively thin HttpClient wrapper). If we were to move the disposal logic to the HttpClientHandler, now such code that was never having its request content disposed will start to, which is bad and exactly the opposite of what we want. It also causes problems for chains of handlers, e.g. if HttpClient is given a handler that wraps CurlHandler, and that handler expects to be able to look at the request content after the SendAsync Task from CurlHandler completes but before it itself completes its SendAsync Task. And while such a scenario may seem far fetched, we effectively have it in the bits today: the diagnostic handler that's used to pass details off to DiagnosticListeners is injected in the middle like this, and it does pass off the request content after the wrapped SendAsync Task completes... if a listener was expecting a non-disposed request content at that point, it would be sorely disappointed.
- Simply stop disposing. The primary downside here is existing code that may have expected disposal to happen, e.g. if a StreamContent wrapping a FileStream isn't explicitly disposed of by the app code, cleanup of the FileStream will be left to its finalizer.
The least bad option is to simply stop disposing. This PR makes that change.
Commit migrated from https://github.com/dotnet/corefx/commit/6d06c39857f8bb7a798ca118944d25a43aaa8beb
Fixed a test bug in PostAuthHelper which caused the wrong entity-body
semantics to get used during the test. This actually exposed a netfx
bug dealing with ambiguous semantics (Content-Length vs. chunked).
After fixing this test bug, it then exposed a product bug where we
leak an InvalidOperationException that isn't wrapped properly by an
HttpRequestException. The scenario that exposed this related to
POST'ing content that is non-rewindable and having to resubmit the
POST due to authentication challenges. This test was passing on
.NET Core because the test was written using the wrong assumptions.
It failed on .NET Framework which exposed the problem.
The InvalidOperationException comes from when a StreamContent's
SerializeToStreamAsync method is called and the content needs to be rewound.
If the content can't be rewound, then the exception is thrown with the
error message "The stream was already consumed. It cannot be read again."
Updated the WinHttpHandler and CurlHandler to wrap the InvalidOperationException
in an HttpRequestException. Updated the test accordingly.
Fixesdotnet/corefx#17621.
Commit migrated from https://github.com/dotnet/corefx/commit/e7e3c581870787d87393e674db22589ad56e944c
Finished investigation of failures on .NET Framework for
System.Net.Http.
Added specific NETFX test changes where necessary. Opened up additional
bugs for investigation.
Added missing parameter validation for HttpClientHandler.MaxConnectionsPerServer
for the net46 OOB. This matches .NET Core now.
Removed some test code that was incorrectly trying to do CredentialCache.Add()
with a 'basic' authtype and using DefaultCredentials. This is invalid and
throws exception on netfx. Added dotnet/corefx#18870.
Remove PlatformNotSupportedProxy test code. It was throwing an exception
on netfx and the purpose of it didn't seem to make sense in the one test
that was using it.
Fixesdotnet/corefx#17691.
Commit migrated from https://github.com/dotnet/corefx/commit/b1246c7f1ee1d9e42594988073fd06580d23fe84
Now instead of Use*Key a project can instead define the assembly key
in the project (genreally the common dir.pops for a project) using
the AssemblyKey property. The accepted values are Open, ECMA, MSFT,
Test.
This change allows for a repo to set the default key they want to use
for projects. In corefx we have switched the default to use the Open
key instead of the old BuildTools default of MSFT key.
As part of this update we are explicitly setting the AssemblyKey in
all the library projects (although it is really only necessary for
projects that aren't the default).
Also with this change we are updating all the new libraries that have
not yet shipped stable (compared to our 1.1 release) and making them
use the Open key. Which means that for prerelease dependencies there
might be some binary breaking changes to consume.
The following libraries ahven't shipped so there key is being
changed from MSFT to Open:
Microsoft.XmlSerializer.Generator
System.CodeDom
System.Configuration.ConfigurationManager
System.Data.Odbc
System.DirectoryServices
System.DirectoryServices.AccountManagement
System.DirectoryServices.Protocols
System.IO.Ports
System.Json
System.Memory
System.Net.HttpListener
System.Net.Mail
System.Net.ServicePoint
System.Net.WebClient
System.Net.WebProxy
System.Private.Xml
System.Private.Xml.Linq
System.Security.Cryptography.Xml
System.Security.Permissions
System.Transactions.Local
System.Web.HttpUtility
Commit migrated from https://github.com/dotnet/corefx/commit/ac09a797d09502ebab61f7167bb856846602e1e6
It should not be possible by construction for _pendingReadRequest to become null in SignalComplete after we check it for nullness, as all access to it is protected by a lock. But for good measure, store it into a local and use that local for subsequent accesses. If nothing else, we can avoid an extra field access.
Commit migrated from https://github.com/dotnet/corefx/commit/7dc759724bd3da68ebe3756f1e3ffa9bd9266d2c
It looks like it's possible in a rare situation for the following to occur and result in a NullReferenceException when finalizing a request:
- HttpClient.SendAsync is called, which creates an EasyRequest. That EasyRequest isn't yet associated with a MultiAgent.
- The request is queued to the MultiAgent.
- Between the time that the request is queued and it's handled, the associated CancellationToken has cancellation requested.
- When the agent then processes the request, in ActivateNewRequest it'll see that cancellation has been requested and will immediately bail, before associating the easy request with the agent.
- Everything is dropped and eventually finalized. At that point the response stream's finalizer is invoked, it calls SignalComplete(..., forceCancel:true), and that dereferences _associatedMultiAgent in order to issue a cancellation request... but _associatedMultiAgent hasn't yet been set.
There's no reason _associatedMultiAgent's initialization needs to be deferred until the EasyRequest is picked up by the agent. We can instead make _associatedMultiAgent a readonly field that's initialized to the associated agent when the EasyRequest is constructed, so it won't be null even in such a situation.
Commit migrated from https://github.com/dotnet/corefx/commit/534a8dcd35bd3f264d08eadfe54a49e859e2012e
* Fix MaxResponseHeadersLengthSemantics
The new HttpClientHandler.MaxResponseHeadersLength property is defined differently from the similarly
named WebRequestHandler and HttpWebRequest properties. The units are supposed to be in Kilobytes
(1024 bytes). This problem was discovered while doing .NET Core vs. .NET Framework compat testing.
Fix the semantics to match the existing WebRequestHandler and HttpWebRequest properties. Adjust tests.
Contributes to dotnet/corefx#17691
* Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/170f7a5ac7f98f2076f0776c573e3188a390d565
Got the Http Functional tests running with no errors against NETFX (Desktop). Found a bunch
of compatibility differences between Desktop and Core that need to be investigated. For now,
the tests are skipped on Desktop.
Fixed the LoopbackServer so that it will run. It was blowing up with `MissingTypeException`
due to missing SocketTaskExtensions class (dotnet/corefx#17690).
Contributes to dotnet/corefx#17691
Commit migrated from https://github.com/dotnet/corefx/commit/b7f6f5f159ebe6c0597578bbd858697a6159a22f