473,839 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Web Exception: 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.Crea te("http://proxima/test.html");
using (HttpWebRespons e resp =
(HttpWebRespons e)req.GetRespon se())
{
byte[] buffer = new byte[1024*1024];
int read = 0;
Stream stream = resp.GetRespons eStream();
do
{
read = stream.Read(buf fer, 0, 1024*1024);
}
while (read !=0);
stream.Close();
resp.Close();
req = null;
}

if (i % 1000 == 0)
Console.WriteLi ne(i);
}
Console.WriteLi ne(i);
}
catch (Exception ex)
{
Console.WriteLi ne("Exception at iteration " + i);
Console.WriteLi ne( 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.WebC lient.
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 1620

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

Similar topics

7
9297
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. # No warranty express or implied for the accuracy, fitness to purpose
3
490
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
2015
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 hits the Back button to return to the page in question. At that point, shouldn't the Page_Load event fire for the page since it was set to expire immediately? Thanks Timo
35
11435
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 Then CType(cn, IDisposable).Dispose() End If I have to admit, I'm not sure what happens here. Will someone explain this line of code (the middle one, not the if statement LOL) to me please?
2
1159
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
3641
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 tried SQL Server connection, SSPI integrated or not, OledB (mdb) connection with enclosed password in the connection string, but I get consistently the same error. I've even tried to deinstall/reinstall Framework (1.1 SP1), IIS (5.1), S.O.(WXp SP2)...
7
2214
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 : 1. Connection object is a reference type object . 2. All reference types are passed by reference even when done without using modifier like ref / out .
14
4621
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 _ ("Server=server1; database=db1;user id=user1;password=whatever") Dim objDataAdapter As New SqlDataAdapter() Dim objDataSet
4
4769
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
9698
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10911
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10589
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10654
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7833
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4494
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4066
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.