Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: PushStreamContent is swallowing exception [910]

$
0
0
I am using HttpClient and PushStreamContent to upload 1GB of data. I noticed that if I do _not_ use the try-catch below, I am not seeing any exception thrown. Actually there is an out-of-memory exception being thrown by HttpClient here. Re-enable the commented try-catch block and you should see the problem.

__Attached__ a standalone repro.

```
// 1. PushStreamContent (this is not seekable)
request.Content = new PushStreamContent((requestStream, content, transportContext) =>
{
//try
//{
using (requestStream)
{
for (long i = 0; i < iterations; i++)
{
// writing chunks of 1KB to the wire
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Flush();
}

if (remainingBytes > 0)
{
requestStream.Write(buffer, 0, (int)remainingBytes);
requestStream.Flush();
}
}
//}
//catch (Exception ex) //NOTE: without this try-catch block, i do not see any error thrown
//{
// Console.WriteLine("Exception occurred while writing to request stream:\n{0}\n", ex.ToString());
//}
});
```
Comments: Some notes from Kiran's investigation: > Yeah, right, the data is getting buffered at the client before its being sent and since the user was sending huge files, they were seeing OutOfMemoryException. > >We came to know later that HttpClient is buffering here because when PushStreamContent is used we do not set Content-Length header and expect the content to be sent in chunked transfer encoding, but it seems HttpClient was designed this way as many servers do not accept chunked encoded data. So, we addressed the user’s issue by explicitly setting the ‘request.Headers.TransferEncodingChunked=true’. > >I do not think this bug is super important, but it did take me some time to figure out the issue (as I wasn’t seeing the exception that the client was reporting). That said, I think the user’s usage here is incorrect as I think they should be using the StreamContent rather than PushStreamContent.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>