[Mono-list] HttpWebRequest.GetResponse() can trigger an uncatchable exception

Christopher David Howie me at chrishowie.com
Sun Jul 10 05:31:10 EDT 2011


 On Sat, 9 Jul 2011 11:50:34 -0400, Gonzalo Paniagua Javier wrote:
> Not much I can do without a test case.

 I know.  :(  The worst bug is the one that only happens once in a blue 
 moon.

> I'd say that this is a problem reusing a connection and somehow 2
> threads "own" the same stream. Set KeepAlive to false (and increase
> the number of file descriptors! (ulimit)) and see if you can still
> reproduce the problem. If it does not happen, bingo! Reduce the
> 'maxconnections' setting via app.config file to 1 and begin as many
> requests as possible to the same URL. If you can reproduce it this
> way, it's easier to find when 2 threads are using the same stream.

 I'm using the following code:

 ---------->8----------
 using System;
 using System.Linq;
 using System.Net;
 using System.Threading;

 internal class Program
 {
     private static string url;

     private const int THREAD_COUNT = 1000;

     private static void Main(string[] args)
     {
         ServicePointManager.DefaultConnectionLimit = 1;

         url = args.Length > 0 ? args[0] : "http://localhost/";

         var threads = new Thread[THREAD_COUNT];

         for (int i = 0; i < THREAD_COUNT; i++) {
             threads[i] = new Thread(WorkerThread);
             threads[i].Start();
         }

         for (int i = 0; i < THREAD_COUNT; i++) {
             threads[i].Join();
         }
     }

     private static void WorkerThread()
     {
         for (;;) {
             var request = (HttpWebRequest)WebRequest.Create(url);
             request.KeepAlive = false;

             try {
                 using (request.GetResponse())
                     Console.Write('.');
             } catch {
                 Console.Write('!');
             }
         }
     }
 }
 ---------->8----------

 So far (10+ minutes) no exception has been thrown by this test.  I'd be 
 open to suggestions on how to tweak it.

> Also check the values of the variables involved in that BlockCopy 
> call
> and the values of readBuffer* before the call.

 I know that readBufferOffset is -1.  I'm not sure about the others.  If 
 we can get a consistent repro then I'll be able to check pretty easily.

-- 
 Chris Howie
 http://www.chrishowie.com
 http://en.wikipedia.org/wiki/User:Crazycomputers

 If you correspond with me on a regular basis, please read this 
 document: http://www.chrishowie.com/email-preferences/

 PGP fingerprint: 2B7A B280 8B12 21CC 260A DF65 6FCE 505A CF83 38F5

 ------------------------------------------------------------------------
                     IMPORTANT INFORMATION/DISCLAIMER

 This document should be read only by those persons to whom it is 
 addressed.  If you have received this message it was obviously addressed 
 to you and therefore you can read it.

 Additionally, by sending an email to ANY of my addresses or to ANY 
 mailing lists to which I am subscribed, whether intentionally or 
 accidentally, you are agreeing that I am "the intended recipient," and 
 that I may do whatever I wish with the contents of any message received 
 from you, unless a pre-existing agreement prohibits me from so doing.

 This overrides any disclaimer or statement of confidentiality that may 
 be included on your message.


More information about the Mono-list mailing list