BUG: HttpWebResponse is not disposed RRS feed

  • Question

  • User-999598023 posted

    While reflecting on the code looking for the issue with incorrect duplicates being reported: http://forums.iis.net/p/1163713/1929353.aspx

    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.

    Monday, December 28, 2009 4:44 PM

All replies

  • User-47214744 posted

    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.

    Friday, January 8, 2010 2:50 PM
  • User-999598023 posted

    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.

    Friday, January 15, 2010 4:43 PM