[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:27:03 -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 01:07:11 2003
+++ shadow/45463.tmp.18718	Sun Jul 20 02:27:03 2003
@@ -223,6 +223,118 @@
 
 
 ------- Additional Comments From miguel@ximian.com  2003-07-20 01:07 -------
 Ok, it is even simpler: the delay is not required;  it is a matter of
 the size of the data being received that might make it fail.  Remove
 the sleep, it will fail just as badly.
+
+------- Additional Comments From miguel@ximian.com  2003-07-20 02:27 -------
+Ok, the sample above is obviously broken.  
+
+Here are the new versions that actually show the problem.
+
+The bug is not in the sleep *in the middle* of a chunked request, that
+works fine;  The problem is if you sleep between one chunked block and
+the next.
+
+use IO::Socket;
+ use Net::hostent;              # for OO version of gethostbyaddr
+
+ $PORT = 9000;                  # pick something not in use
+
+ $server = IO::Socket::INET->new( Proto     => 'tcp',
+                                  LocalPort => $PORT,
+                                  Listen    => SOMAXCONN,
+                                  Reuse     => 1);
+
+sub ss {
+    my ($s) = @_;
+    $l = length ($s);
+    printf "Sending: %x %s\n", $l, $s;
+    printf $client "%x\r\n", length ($s);
+    print $client "$s\r\n";
+}
+
+sub slow {
+    my ($a, $b) = @_;
+    $l = length ($a) + length ($b);
+    printf "Sending: %x %s and %s\n", $l,$a, $b;
+    printf $client "%x\r\n", $l;
+    print $client "$a";
+    print $client "$b\r\n";
+}
+
+while ($client = $server->accept()) {
+   $client->autoflush(1);
+   $a = <$client>; print "$a";
+   $a = <$client>; print "$a";
+   $a = <$client>; print "$a";
+
+   print $client "HTTP/1.1 200 OK\n";
+   print $client "Date: Thu, 26 Jun 2003 19:20:46 GMT\n";
+   print $client "Set-Cookie:
+PREF=ID=41462726307f3c15:TM=1056655246:LM=1056655246:S=U--vIvENfVsOsKF7;
+expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com\n";
+   print $client "Cache-control: private\n";
+   print $client "Content-Type: text/html\n";
+   print $client "Transfer-Encoding: chunked\n";
+   print $client "Server: GWS/2.1\n";
+   print $client "\n";
+   ss "<html><body>";
+   ss "La de da\n";
+   slow "123456789", "abcdefghijk";
+   sleep 5;
+   ss "La de da";
+   ss "</body></html>";
+   close $client;
+ }
+
+
+And C#
+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 ();
+		StreamReader input = new StreamReader (resp.GetResponseStream ());
+
+		string buf;
+		bool feof = false;
+				     
+		do {
+			buf = input.ReadLine ();
+
+			if (buf == null)
+				feof = true;
+			else {
+				Console.WriteLine (String.Format ("buf: {0}", buf));
+			}
+
+
+		} while (!feof);
+	}
+}
+
+This time the output should be:
+
+<html><body>La de da
+123456789abcdefghijkLa de da</body></html>
+
+While Mono gets;
+buf: <html><body>La de da
+buf: 123456789abcdefghijk
+
+
+
+
+
+
+
+
+