473,387 Members | 1,541 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,387 software developers and data experts.

Will the "Underlying connection closed" bug be fixed?

I don't get the message so it's hard to debug that, but some of my
clients report that they get "The underlying connection was closed
unexpectedly" exception. According to this site (http://
http://www.dotnetspider.com/resource...nnection.aspx),
it's a bug of .NET 2.0, and the author suggests that we use
KeepAlive=false until Microsoft fixes it.

It seems like almost 5 years have passes since the release of .NET
2.0, and this stilll exists. Should I wait for the fix, or use
KeepAlive=false instead?
Oct 24 '08 #1
4 4524
On Fri, 24 Oct 2008 14:58:45 -0700, Sin Jeong-hun <ty*******@gmail.com>
wrote:
I don't get the message so it's hard to debug that, but some of my
clients report that they get "The underlying connection was closed
unexpectedly" exception. According to this site (http://
http://www.dotnetspider.com/resource...nnection.aspx),
it's a bug of .NET 2.0, and the author suggests that we use
KeepAlive=false until Microsoft fixes it.

It seems like almost 5 years have passes since the release of .NET
2.0, and this stilll exists. Should I wait for the fix, or use
KeepAlive=false instead?
You should either set KeepAlive to false or, much better, simply write
your code to tolerate a closed connection.

My cursory reading of the HTTP specification suggests that there is no
reason for a client to expect an HTTP server to keep the connection open
indefinitely, even when "Connection: Keep-Alive" is sent. Even if the
protocol indicated that it should (and as near as I can tell, it doesn't),
a connection can _always_ wind up closed or reset for some other reason.

In other words, in spite of that author's insistence that this is a bug
that Microsoft needs to fix, I see no evidence of that. It appears to be
a natural consequence of an HTTP server behaving normally.

So, any code should be prepared for an error like that, and deal with it
appropriately. Probably the most sensible thing to do, at least the first
time you get the error for a given request, is to simply make a new
connection and request to the server. That's what a web browser would do,
if it opened a connection to an HTTP server and found the connection
closed when it tried to reuse it later.

Pete
Oct 24 '08 #2
Thanks. I created separate WebRequests for each request using
WebRequest.Create(), and common underlying connection seems to be managed by
the .NET framework. I didn't explicitly tell .NET framework to use the same
connection for every requests. And it also looks like there is no way access
the underlying connection (opened by the .NET framework), to check if the
connection is closed or not before sending the request.

Shouldn't the .NET framework check if the connection is closed or not , then
open and use a new connection if it has been closed by web server before
sending a new request ? Checking this for every request and try again seems
to be a lot of typing overhead.

If .NET doesn't do that, is there any way to check if the underlying
connection is closed or not before sending the request?

"Peter Duniho" wrote:
On Fri, 24 Oct 2008 14:58:45 -0700, Sin Jeong-hun <ty*******@gmail.com>
wrote:
I don't get the message so it's hard to debug that, but some of my
clients report that they get "The underlying connection was closed
unexpectedly" exception. According to this site (http://
http://www.dotnetspider.com/resource...nnection.aspx),
it's a bug of .NET 2.0, and the author suggests that we use
KeepAlive=false until Microsoft fixes it.

It seems like almost 5 years have passes since the release of .NET
2.0, and this stilll exists. Should I wait for the fix, or use
KeepAlive=false instead?

You should either set KeepAlive to false or, much better, simply write
your code to tolerate a closed connection.

My cursory reading of the HTTP specification suggests that there is no
reason for a client to expect an HTTP server to keep the connection open
indefinitely, even when "Connection: Keep-Alive" is sent. Even if the
protocol indicated that it should (and as near as I can tell, it doesn't),
a connection can _always_ wind up closed or reset for some other reason.

In other words, in spite of that author's insistence that this is a bug
that Microsoft needs to fix, I see no evidence of that. It appears to be
a natural consequence of an HTTP server behaving normally.

So, any code should be prepared for an error like that, and deal with it
appropriately. Probably the most sensible thing to do, at least the first
time you get the error for a given request, is to simply make a new
connection and request to the server. That's what a web browser would do,
if it opened a connection to an HTTP server and found the connection
closed when it tried to reuse it later.

Pete
Oct 24 '08 #3
On Fri, 24 Oct 2008 16:13:01 -0700, Tester
<Te****@discussions.microsoft.comwrote:
[...]
Shouldn't the .NET framework check if the connection is closed or not ,
then
open and use a new connection if it has been closed by web server before
sending a new request ? Checking this for every request and try again
seems
to be a lot of typing overhead.

If .NET doesn't do that, is there any way to check if the underlying
connection is closed or not before sending the request?
I'm not sure. I have barely used the WebRequest stuff, so I'm not sure
what level of control you have over the underlying connection.

I suppose if it turns out that as the client code, you have _no_ control
over the connection then my previous reply isn't quite right, as Microsoft
_should_ at least provide that, if not automatically deal with a closed
connection.

Now, all that said, if there's a bug in the framework, it's hard to see
how Microsoft would necessarily be expected to fix it, unless someone
reports it. If someone has reported it, there should be a bug in the
database at http://connect.microsoft.com/ If no one has reported it, then
your first step, assuming you want the bug fixed, would be to report it.

Pete
Oct 24 '08 #4
On Fri, 24 Oct 2008 16:13:01 -0700, Tester
<Te****@discussions.microsoft.comwrote:
[...]
If .NET doesn't do that, is there any way to check if the underlying
connection is closed or not before sending the request?
For what it's worth, it looks to me as though you might be able to control
the connection state by getting the ServicePoint from the HttpWebRequest,
as well as the ConnectionGroupName, and then pass that name to the
ServicePoint.CloseConnectionGroup() method.

As I mentioned, I don't have a lot of experience in this area, but that
might accomplish what you want. It might even be what Microsoft intends
for you to do when the connection is closed by the server. :)

Yet another possible alternative would be to set the
ServicePoint.MaxIdleTime low enough that the ServicePoint always closes
the connection before the server winds up doing it. How well that would
work probably depends on the actual servers you're dealing with, but I'd
guess a _really_ low MaxIdleTime would probably be less than any server
you might run into.

Pete
Oct 24 '08 #5

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

Similar topics

2
by: Dave | last post by:
These code generates the error: WebRequest request = WebRequest.Create("http://www.yahoo.com"); WebResponse response = request.GetResponse(); Here is the stack trace for the error: ...
0
by: jwalton | last post by:
I have a new Web Service (written in C#) that is giving me major problems. The Consumer application is written in VB.NET. When executed totally on localhost it works 100%. When standalone Web...
4
by: David Cho | last post by:
Hi, this is just plain strange. This is my code. HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.yahoo.com"); request.Method = "POST"; request.ContentType =...
6
by: karim | last post by:
I have an asp.net page that stopped running properly giving the error below. The app uses a SQL Server 2000 on another server. Enterprise Manager and Query analyzer on the web server can connect to...
0
by: lpinho | last post by:
Hi There, I've generated a C# file from a wsdl file using wsdl.exe utility. Then I created a console application and made a call to the method generated, first I got the error: "The request...
0
by: Steve | last post by:
Hi!, I'm using WebRequest to post a URL. But, sometimes, this tell me the error "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.". I...
0
by: Systemino | last post by:
Hallo, I have a site developed on ASP.NET 2.0. It stay on my notebook and it works with a ORACLE database (ver. 9.0). It's all right!! Then I reached my definite site version on IIS 6.0 in...
1
by: Sin Jeong-hun | last post by:
Some of my clients (but I don't) get the "The underlying connection was closed" exception. According to this article (http://...
1
by: Gx3r0 | last post by:
0I have a windows service I created that checks for data to post to an off site webservice over SSL. The service checks every 10 seconds for data to send, if there is data it opens a connection to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.