[Mono-dev] HttpWebResponse ConnectStream blocks on empty stream
Arne Claassen
arnec at mindtouch.com
Tue Feb 3 12:29:13 EST 2009
I've been having a problem with HttpWebResponse locking up on
GetResponseSream and BeingGetResponseStream never returning on
responses that have no content-length header and no content. On .NET
this will return immediately, but on mono (1.9.1, 2.0.1 and 2.02) the
read will block only to be killed if the request itself has a timeout.
A simple repro is to his a site, get it's Etag/LastModified and hit it
again for the 304 response which should have no content. However
getting that response stream still shouldn't lock up.
I couldn't find a bug on this yet, but wanted to check here before
filing.
Repro -----------------------------------------------------
using System;
using System.IO;
using System.Net;
namespace BugRepro {
class Program {
const string URL = "http://blog.developer.mindtouch.com/feed/";
static void Main(string[] args) {
// first request (which should be 200)
HttpWebRequest request = WebRequest.Create(URL) as
HttpWebRequest;
request.Method = "GET";
HttpWebResponse response =
(HttpWebResponse)request.GetResponse();
Console.WriteLine("response: {0}", response.StatusCode);
Stream stream = response.GetResponseStream();
byte[] buffer = new byte[4096];
int read = stream.Read(buffer, 0, buffer.Length);
Console.WriteLine("{0} bytes read", read);
stream.Close();
// second request which should be 304)
request = WebRequest.Create(URL) as HttpWebRequest;
request.Method = "GET";
request.Headers.Add(HttpRequestHeader.IfNoneMatch,
response.Headers[HttpResponseHeader.ETag]);
request.IfModifiedSince = response.LastModified;
response.Close();
try {
response = (HttpWebResponse)request.GetResponse();
} catch(WebException e) {
response = (HttpWebResponse)e.Response;
}
Console.WriteLine("response: {0}", response.StatusCode);
stream = response.GetResponseStream();
buffer = new byte[4096];
read = stream.Read(buffer, 0, buffer.Length);
// don't get here until the request timeout hits
Console.WriteLine("{0} bytes read", read);
stream.Close();
}
}
}
Repro -----------------------------------------------------
Arne Claassen
MindTouch
San Diego, CA
http://twitter.com/sdether
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20090203/ed80f3ba/attachment-0001.html
More information about the Mono-devel-list
mailing list