[Mono-bugs] [Bug 45463][Wis] Changed - WebResponse returning NULL half-way through stream sometimes

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Sun, 20 Jul 2003 02:54:37 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by miguel@ximian.com.

http://bugzilla.ximian.com/show_bug.cgi?id=45463

--- shadow/45463	Sun Jul 20 02:27:03 2003
+++ shadow/45463.tmp.19550	Sun Jul 20 02:54:36 2003
@@ -335,6 +335,66 @@
 
 
 
 
 
 
+
+------- Additional Comments From miguel@ximian.com  2003-07-20 02:54 -------
+Ok, we found the real source of the problem.
+
+We are not supposed to return 0 from a call to Read when there is
+still data available on a stream;  The ChunkedStream will return 0 if
+there is no more data available *at the time of invocation* even if
+there is more data pending.
+
+At that point something in the stack should sleep until more data
+becomes available, and return at that point.
+
+The following simple program on .NET will never return 0 until the end
+(Well, .NET returns -1 at the end, against its own specifications),
+the output on .NET is:
+Read 12 bytes
+Read 9 ytes
+Read 9 bytes
+Read 11 bytes    <--- here there is a 5 second pause --->
+read 8 bytes
+Read 14 bytes
+Read -1 bytes
+Done.
+
+On Mono, this is what we get:
+
+Read 41 bytes
+Read 0 bytes
+Done
+
+41 bytes are the bytes for the first four chunks (then we sleep), and
+we return 0.
+
+Sample C# program attached, use the same Perl program.
+
+using System;
+using System.IO;
+using System.Net;
+
+class Test {
+
+	static void Main ()
+	{
+		string url = "http://localhost:9000/";
+		
+		HttpWebRequest req = (HttpWebRequest)WebRequest.Create (url);
+		WebResponse resp = req.GetResponse ();
+		Stream s = resp.GetResponseStream ();
+
+		byte [] b = new byte [1024];
+
+		int c;
+		do {
+			c = s.Read (b, 0, 1024);
+			Console.WriteLine ("Read {0} bytes", c);
+		} while (c > 0);
+		Console.WriteLine ("Done");
+	}
+}
+