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