InfiniTec - Henning Krauses Blog

Don't adjust your mind - it's reality that is malfunctioning

HttpWebRequest fails when several connections are made concurrently

Affected products

  • .NET Framework 1.0
  • .NET Framework 1.1

Summary

When making several connections concurrently with the HttpWebRequest class, the request objects fail with an exception.

Symptoms

When making several connections concurrently (more than 12 on a single processor machine) with the HttpWebRequest class, the request objects fail with an exception.
If these calls are made from methods running on ThreadPool thhreads, the maximum number of connections is further reduced.

Cause

The HttpWebRequest uses two threads for each connection from the ThreadPool. This pool has a maximal capacity of 25 on one processor machines. Regularly, if the pool is full, it would queue further requests. But the HttpWebRequest class checks whether two threads are available before putting its requests into the queue. It fails with an exception, when there are less than two threads available.

Status

This behaviour is by design.

Solution

Keep concurrent connections as low as possible, and don't initiate requests from methods running on ThreadPool threads.

Other information

To keep the concurrent connections low, you can use the Advanced Threadpool from the Toolbox area of this page. This class implements a thread pool, which is independent of the ThreadPool class. With this class, you can set the maximium number of concurrent threads, so that the limit of the ThreadPool is never reached.

Posted by Henning Krause on Friday, December 31, 2004 1:09 PM, last modified on Friday, December 31, 2004 1:10 PM
Permalink | Post RSSRSS comment feed