Bug 3876 - HttpWebRequest chunked reading problem
Summary: HttpWebRequest chunked reading problem
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-03-13 12:43 UTC by Gonzalo Paniagua Javier
Modified: 2012-03-13 12:48 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test that shows the difference between .NEt and Mono (5.56 KB, application/x-zip-compressed)
2012-03-13 12:44 UTC, Gonzalo Paniagua Javier
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Gonzalo Paniagua Javier 2012-03-13 12:43:06 UTC
From Mårten Ekblad in mono-list:

I have created a client app that communicates with a web service that uses the Comet way of sending events to a client. To do that I start a "long-living" HttpWebRequest to the server. The server communicates back to the client by sending chunked content (Transfer-Encoding: chunked). Individual events are then transferred in chunks. The problem for me here is that Mono seems to wait for the connection to terminate or the timeout to happen before sending the chunks back to the consumer of HttpWebRequest. This is not the case in .Net. In .Net each chunk is reported back individually when they arrive.
This is the pseudo code I'm using:
1. HttpWebRequest req = WebRequest.Create( URL...);
2. req.BeginGetRequestStream(...);
3. stream = eventContext.WebRequest.EndGetRequestStream(...);
4. StreamWriter writer = new StreamWriter(stream);
5. writer.Write(data);
6. writer.Close();
7. eventContext.RequestStream.Close();
8. eventContext.WebRequest.BeginGetResponse(...);
9. HttpWebResponse resp = (HttpWebResponse) req.EndGetResponse(asynchronousResult);
10. responseStream = resp.GetResponseStream();
11. responseStream.BeginRead(eventContext.Buffer, 0, 20000, new AsyncCallback(DataReceived), eventContext);
12. In DataReceived I do responseStream.EndRead(asynchronousResult);
13. After that I arm the read again with responseStream.BeginRead(...);


In .Net DataReceived is called on each packet. In Mono it's called after 30 seconds (probably the timeout).

Is this the intended behavior with HttpWebRequest and chunked content? Is there another recommended way of dealing Comet style web services?
Comment 1 Gonzalo Paniagua Javier 2012-03-13 12:44:00 UTC
Created attachment 1509 [details]
Test that shows the difference between .NEt and Mono
Comment 2 Gonzalo Paniagua Javier 2012-03-13 12:48:24 UTC
Fixed in mono-2-10/bad8aa4 and master/864d354