HighTechTalks DotNet Forums  

Bug in HttpWebRequest/Response Dispose() implementation?

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss Bug in HttpWebRequest/Response Dispose() implementation? in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Vagif Abilov
 
Posts: n/a

Default Bug in HttpWebRequest/Response Dispose() implementation? - 07-05-2006 , 03:29 PM






Hello,

We have a simple piece of code that exchanges data using HTTP
request/reponse. It uses "using" statement to guarantee that the
communication channel is properly closed on completion. However, if the code
is executed multiple times, the first execution attempt works fine, but the
second attempt times out.

To verify if the channel is closed properly, we replaced that code with the
following:

HttpWebRequest request = PrepareRequest(userVerificationData,
schufaRequestType, null);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

string requestID = response.Headers["RequestID"];
try
{
// Do something
}
finally
{
request = null;
response = null;
GC.Collect();
}

Then suddently everything worked! But the difference is that now we call
expensive garbage collection which of course kills the performance.

Why using Dispose method does not do the same? Isn't it the purpose of
IDisposable interface?

Vagif Abilov
Oslo Norway



Reply With Quote
  #2  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: Bug in HttpWebRequest/Response Dispose() implementation? - 07-05-2006 , 03:52 PM






Vagif Abilov <vagif (AT) online (DOT) no> wrote:
Quote:
Hello,

We have a simple piece of code that exchanges data using HTTP
request/reponse. It uses "using" statement to guarantee that the
communication channel is properly closed on completion. However, if the code
is executed multiple times, the first execution attempt works fine, but the
second attempt times out.
<snip>

Quote:
Why using Dispose method does not do the same? Isn't it the purpose of
IDisposable interface?
Yes. Could you show us the code that doesn't work, preferrably as a
short but complete program?

--
Jon Skeet - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Reply With Quote
  #3  
Old   
Barry Kelly
 
Posts: n/a

Default Re: Bug in HttpWebRequest/Response Dispose() implementation? - 07-05-2006 , 04:02 PM



"Vagif Abilov" <vagif (AT) online (DOT) no> wrote:

Quote:
We have a simple piece of code that exchanges data using HTTP
request/reponse. It uses "using" statement to guarantee that the
communication channel is properly closed on completion. However, if the code
is executed multiple times, the first execution attempt works fine, but the
second attempt times out.

To verify if the channel is closed properly, we replaced that code with the
following:
I'm not sure I understand - can you show us the code that didn't work,
rather than the code that did?

-- Barry

--
http://barrkel.blogspot.com/


Reply With Quote
  #4  
Old   
Vagif Abilov
 
Posts: n/a

Default Re: Bug in HttpWebRequest/Response Dispose() implementation? - 07-05-2006 , 04:47 PM



I am not in the office right now, but I guess the original code looked like
this:

HttpWebRequest request = PrepareRequest(...);
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
... do something with response
}

HttpWebRequest is not disposable, so we applied "using" pattern to
HttpWebResponse object only.

While searching for the source of the problem, I found couple of documents:

http://dturini.blogspot.com/2004/06/...with-some.html

http://support.microsoft.com/?kbid=831138

Looks like there .NET 1.1 had a problem with release of unmanaged resources
allocated by HttpResponse. Does .NET 2.0 has the same problem?

Vagif


"Jon Skeet [C# MVP]" <skeet (AT) pobox (DOT) com> wrote

Quote:
Vagif Abilov <vagif (AT) online (DOT) no> wrote:
Hello,

We have a simple piece of code that exchanges data using HTTP
request/reponse. It uses "using" statement to guarantee that the
communication channel is properly closed on completion. However, if the
code
is executed multiple times, the first execution attempt works fine, but
the
second attempt times out.

snip

Why using Dispose method does not do the same? Isn't it the purpose of
IDisposable interface?

Yes. Could you show us the code that doesn't work, preferrably as a
short but complete program?

--
Jon Skeet - <skeet (AT) pobox (DOT) com
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too



Reply With Quote
  #5  
Old   
Vagif Abilov
 
Posts: n/a

Default Re: Bug in HttpWebRequest/Response Dispose() implementation? - 07-05-2006 , 04:48 PM



Please see my reply to Jon Skeet.

Best regards
Vagif


"Barry Kelly" <barry.j.kelly (AT) gmail (DOT) com> wrote

Quote:
"Vagif Abilov" <vagif (AT) online (DOT) no> wrote:

We have a simple piece of code that exchanges data using HTTP
request/reponse. It uses "using" statement to guarantee that the
communication channel is properly closed on completion. However, if the
code
is executed multiple times, the first execution attempt works fine, but
the
second attempt times out.

To verify if the channel is closed properly, we replaced that code with
the
following:

I'm not sure I understand - can you show us the code that didn't work,
rather than the code that did?

-- Barry

--
http://barrkel.blogspot.com/



Reply With Quote
  #6  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: Bug in HttpWebRequest/Response Dispose() implementation? - 07-05-2006 , 05:27 PM



Vagif Abilov <vagif (AT) online (DOT) no> wrote:
Quote:
I am not in the office right now, but I guess the original code looked like
this:

HttpWebRequest request = PrepareRequest(...);
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
... do something with response
}

HttpWebRequest is not disposable, so we applied "using" pattern to
HttpWebResponse object only.

While searching for the source of the problem, I found couple of documents:

http://dturini.blogspot.com/2004/06/...with-some.html

http://support.microsoft.com/?kbid=831138

Looks like there .NET 1.1 had a problem with release of unmanaged resources
allocated by HttpResponse. Does .NET 2.0 has the same problem?
Hmm. Glad you've found it. I *suspect* that .NET 2.0 doesn't have the
same problem, given that it was fixed against 1.1 in the hotfix. I
wouldn't like to say for sure though.

--
Jon Skeet - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Reply With Quote
  #7  
Old   
Vagif Abilov
 
Posts: n/a

Default Re: Bug in HttpWebRequest/Response Dispose() implementation? - 07-05-2006 , 05:53 PM



Well, the problem we discovered was actually in our code running on .NET 2.0
:-(

We will investigate more, but first impression - the problem is still there,
since "using" does not work and GC.Collect does.

Vagif


"Jon Skeet [C# MVP]" <skeet (AT) pobox (DOT) com> wrote

Quote:
Vagif Abilov <vagif (AT) online (DOT) no> wrote:
I am not in the office right now, but I guess the original code looked
like
this:

HttpWebRequest request = PrepareRequest(...);
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
... do something with response
}

HttpWebRequest is not disposable, so we applied "using" pattern to
HttpWebResponse object only.

While searching for the source of the problem, I found couple of
documents:

http://dturini.blogspot.com/2004/06/...with-some.html

http://support.microsoft.com/?kbid=831138

Looks like there .NET 1.1 had a problem with release of unmanaged
resources
allocated by HttpResponse. Does .NET 2.0 has the same problem?

Hmm. Glad you've found it. I *suspect* that .NET 2.0 doesn't have the
same problem, given that it was fixed against 1.1 in the hotfix. I
wouldn't like to say for sure though.

--
Jon Skeet - <skeet (AT) pobox (DOT) com
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.