[Mono-dev] HttpListener hangs with r106513

Casey Marshall cmarshall at pacificbiosciences.com
Tue Jun 24 19:04:35 EDT 2008

I've noticed that it recent SVN mono snapshots (r106513) using
HttpListener and WebRequest in the same process hangs. This doesn't hang
with 1.9.1, and didn't with less recent snapshots.

I haven't tried having the client and server in different processes, and
don't know if it reproduces there.

Test case:

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

class simplehttp
        public static void Main(string[] argv)
                simplehttp sh = new simplehttp();
                Thread srv = new Thread(new ThreadStart(sh.ServerMain));
                srv.Name = "HttpServer";

                for (;;)
                        HttpWebRequest req = (HttpWebRequest) WebRequest.Create ("http://localhost:8888/foobar/");
                        req.ServicePoint.Expect100Continue = false;
                        req.ServicePoint.UseNagleAlgorithm = false;
                        req.Method = "POST";
                        StreamWriter w = new StreamWriter(req.GetRequestStream());
                        w.WriteLine("Hello, server!");

                        HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
                        StreamReader r = new StreamReader(resp.GetResponseStream());
                        System.Console.WriteLine("client reads: {0}", r.ReadToEnd());

        private void ServerMain()
                HttpListener listener = new HttpListener();
                while (true)
                        HttpListenerContext ctx = listener.GetContext();
                        ThreadPool.QueueUserWorkItem(new WaitCallback(HandleConnection), ctx);

        private void HandleConnection(object state)
                HttpListenerContext ctx = (HttpListenerContext) state;
                HttpListenerRequest req = ctx.Request;
                StreamReader r = new StreamReader(req.InputStream);
                System.Console.WriteLine ("server reads {0}", r.ReadToEnd());

                HttpListenerResponse resp = ctx.Response;
                StreamWriter o = new StreamWriter(resp.OutputStream);
                o.WriteLine("Hello, world!");


More information about the Mono-devel-list mailing list