[Mono-list] HttpWebRequest.GetResponse() can trigger an uncatchable exception
James Wright
james.wright at jigsawdezign.com
Sun Jul 10 09:12:31 EDT 2011
Is there a possibility this error is caused by the client dropping
the connection before sending the full request, rather than heavy load?
James
On 10/07/2011 10:31, Christopher David Howie wrote:
> 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.
>
More information about the Mono-list
mailing list