IIS Search Engine Optimization Toolkit
BUG: HttpWebResponse is not disposed
Last post Jan 15, 2010 04:43 PM by mikeon
Dec 28, 2009 04:44 PM|mikeon|LINK
While reflecting on the code looking for the issue with incorrect duplicates being reported:
I've encountered that in private void OnGetContent(UrlInfo urlInfo) in Microsoft.Web.Management.SEO.Crawler.UrlDownloader class, the HttpWebResponse object is never disposed. Since unmanaged resources come into play, in certain scenarios this will lead to
errors with windows running out of native handles.
Confirm if it is a bug and please fix it if so.
Oh and btw, OnGetContent is not a best name for the method since it, unlike all other OnXXXX methods, has nothing to do with event being risen.
Jan 08, 2010 02:50 PM|CarlosAg|LINK
Actually it is not a bug, if you read the documentation you will see the following:
The Close method closes the response stream and releases the connection to the resource for reuse by other requests.
You must call either the Stream..::.Close
or the HttpWebResponse..::.Close method to close the stream and release the connection for reuse.
It is not necessary to call both Stream..::.Close
and HttpWebResponse..::.Close, but doing so does not cause an error. Failure to close the stream can
cause your application to run out of connections.
We always close the ResponseStream and as you can see it is not required to do both.
Regarding the name, as you can see that is a private class that is not meant to be documented so the name really is not an issue, however just to give some historical references and to exaplin what is not clear while reflecting private code is that it was
not originally a URLDownloader class but it was a full Pipeline class which had virtual methods that could be overriden for extensibility reasons (many more than the ones today there) to process multiple protocols and not only HTTP and to aquire content from
other means like databases, however, due to costs (test/dev/pm resource constraints) we decided to reduce the scope and we transformed that into just a simple downloader and remove the pipeline concepts for v1.
Jan 15, 2010 04:43 PM|mikeon|LINK
Thanks for your respones Carlos. I'm aware that in 99% percent of cases Close == Dispose and sometimes it doesn't. Issue is that on this particular object, neither Close nor Dispose is called - ever.