473,326 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Frustrating http connection behaviour in .Net (C#)

(This post also available at
http://roblevine.blogspot.com/2004/1...behaviour.html
in a slightly more readable format!)
Hi All,

I seem to be having a bit of a frustrating time with http connections in
..Net at the moment.
Basically I am working on a project in which many subsystems use http to
communicate with eachother. Once in a while, my .Net client will fail with a
"System.Net.WebException: The underlying connection was closed: Unable to
connect to the remote server." exception.
The remote server can be an IIS server or a Jetty server running on Linux -
I see the same problem with both.

To try and reproduce this problem I wrote a very simple client app that
requests a single static page from a web server. It loops round making the
request repeatedly, up to 100000 times.
Here is the static Main method from my console application:
[STAThread]
static void Main(string[] args)
{
int i = 0;
try
{
for (i = 0; i < 10000; i++)
{

HttpWebRequest req = (HttpWebRequest)
WebRequest.Create("http://proxima/test.html");
using (HttpWebResponse resp =
(HttpWebResponse)req.GetResponse())
{
byte[] buffer = new byte[1024*1024];
int read = 0;
Stream stream = resp.GetResponseStream();
do
{
read = stream.Read(buffer, 0, 1024*1024);
}
while (read !=0);
stream.Close();
resp.Close();
req = null;
}

if (i % 1000 == 0)
Console.WriteLine(i);
}
Console.WriteLine(i);
}
catch (Exception ex)
{
Console.WriteLine("Exception at iteration " + i);
Console.WriteLine( ex.ToString());
}

}

For this example I created a very small html file to put on my server - only
50 bytes.
I see some extremely peculiar behaviour when I run this application;
generally the first time it runs, it will process many thousands of
iterations before falling over with the aforementioned exception. Once it
has failed, if I attempt to run it again straight away the application fails
in a matter of a few 10's or 100's of iterations. Why?
It makes no difference to the overall behaviour if I swap my HttpWebRequest
stuff for a System.Net.WebClient.
It makes no difference if I insert a GC.Collect() in the loop.
What is going on here and what is 'remembering' the fact that the client has
previously failed?

I have to admit to being stumped for the time being.
Does anyone else see this behaviour?

TIA for any help,

Rob Levine

Location: Bristol, UK
Email: rob <underscore> levine <at> hotmail <dot> com
Blog: http://roblevine.blogspot.com

Nov 16 '05 #1
0 1596

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
3
by: sjanie | last post by:
The error code is: Microsoft JScript compilation error '800a03ec' Expected ';' /bicc.nl/Connections/BICCwebsite.asp, line 2 Set Conn = Server.CreateObject("ADODB.Connection") ----^
2
by: Timo | last post by:
I've set my aspx page to expire immediately using the management console, HTTP headers tab. Considering this scenario: a user visits the aspx page in question, then moves to another page, then...
35
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing...
2
by: Terry Olsen | last post by:
Creating a test app to perfect some code before putting it in a production app. Test app works perfectly, doesn't work at all in the production app. Can't figure out why...
4
by: Saverio Tedeschi | last post by:
Hi all gurus, I'm getting a strange behaviour in Web services design: when I try to open a connection, or to fill a DataSet, I get the error in subj (totally unrelated to the actual error). I've...
7
by: Mrinal Kamboj | last post by:
Hi , I am using OracleConnection object from Oracle ODP.net provider and following is the behaviour which i am finding bit strange : To start with my argument is based on followings facts : ...
14
by: martin1 | last post by:
All, I want to check wether db connection/open or not, if not it will post db connection error to user in message box The code is like: Dim objConnection As New SqlConnection _...
4
by: swq22 | last post by:
Which python module is capable of pipelining http requests? (I know httplib can send mulitple requests per tcp connection, but in a strictly serial way. )
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.