Harden several SocketsHttpHandler streams against unexpected Dispose (dotnet/corefx...
authorStephen Toub <stoub@microsoft.com>
Tue, 30 Apr 2019 18:58:25 +0000 (14:58 -0400)
committerGitHub <noreply@github.com>
Tue, 30 Apr 2019 18:58:25 +0000 (14:58 -0400)
commitd59bb4ad4fe2ffe77b17d9a62ba35dc5c3767190
tree2542217acb4022e6cd8b74f3216736689ca0118e
parentff6217d850b2e6cbe573561e2d243a3e3ec2a90f
Harden several SocketsHttpHandler streams against unexpected Dispose (dotnet/corefx#37299)

A few tweaks:
- We hand out the ChunkedEncodingWriteStream and ContentLengthWriteStream to an HttpContent.SerializeToStreamAsync.  If that user code disposes of the Stream, then we end up null ref'ing when we try to finish the processing.  We should instead throw a more descriptive error about the misuse.
- Make the non-pooled response streams slightly more robust against concurrent disposal (which is not a supported use, but it happens).

Commit migrated from https://github.com/dotnet/corefx/commit/422565673deb849b42f656f4a68bec791ee4bed9
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ChunkedEncodingWriteStream.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionCloseReadStream.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ContentLengthWriteStream.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpContentStream.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpContentWriteStream.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RawConnectionStream.cs
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs