[Mono-bugs] [Bug 423156] New: web requests fail if the response stream is not closed

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Sep 4 10:21:12 EDT 2008


           Summary: web requests fail if the response stream is not closed
           Product: Mono: Class Libraries
           Version: unspecified
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.Web
        AssignedTo: mhabersack at novell.com
        ReportedBy: lupus at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

The following program will execute just two requests and all the next ones will
be aborted with a timeout. It works correctly if the stream from WebResponse is
closed (the commented line in do_get ()).
The issue is in the client code, the original bug involved an external server.
Note that the stream needs to be closed even in the case that
GetResponseStream() is not called.

using System;
using System.Net;
using System.IO;
using System.Text;
using System.Threading;

class test {

        static string url = "http://localhost:1876/";
        static int count = 5;
        static int server_count = 0;
        static int client_count = 0;

        static void run_server () {
                HttpListener listener = new HttpListener();
                listener.Prefixes.Add (url);

                while (server_count < count) {
                        HttpListenerContext context = listener.GetContext ();
                        HttpListenerRequest request = context.Request;
                        HttpListenerResponse response = context.Response;
                        string responseString = "my data";
                        byte[] buffer = Encoding.UTF8.GetBytes
                        response.ContentLength64 = buffer.Length;
                        Stream output = response.OutputStream;
                        output.Write (buffer, 0, buffer.Length);

        static void do_get () {
                HttpWebRequest req = WebRequest.Create (url) as HttpWebRequest;
                req.Timeout = 2000;
                HttpWebResponse res = req.GetResponse () as HttpWebResponse;
                Stream stream = res.GetResponseStream ();
                //stream.Close ();
                Console.WriteLine ("got " + client_count++);

        static int Main () {
                Thread server = new Thread (run_server);
                server.Start ();
                Thread.Sleep (500);
                for (int i = 0; i < count; ++i) {
                        do_get ();
                server.Join ();
                if (server_count == count && client_count == count)
                        return 0;
                return 1;

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list