HttpClient does not close RequestStream and hang
On .net 3.5, if request have a content, the RequestStream on WebRequest is not closed/disposed. So the actual request hang indefinitely. If the copy request task is wrapped in using, everything works as expected.
Here is the demo console app https://gist.github.com/sonicflare/c53adaf904fee86a6c340b90946677de
The problem is on this line https://github.com/tunnelvisionlabs/dotnet-httpclient35/blob/master/System.Net.Http/System.Net.Http/HttpClientHandler.cs#L320
And if the code is changed to this, request is going ok
.Then(streamTask =>
{
using (var stream = streamTask.Result)
{
return request.Content.CopyToAsync(stream);
}
});
It's great to hear someone is finding this library useful (potentially, if bugs are fixed :wink:).
I'm thinking the fix should probably look like the following. Would you agree?
.Then(streamTask => request.Content.CopyToAsync(streamTask.Result).Finally(_ => streamTask.Result.Dispose()));
:memo: There is a reasonable chance that #10 would fix this as well.
Yes, your fix is more correct. Yeah, its a great library, together with Tasks backport. I ported https://github.com/PlayFab/consuldotnet to 3.5, and they only use HttpClient and Task/async. It was really pleasant. Sharepoint is the only reason people pay any attention to .net 3.5 :grinning: