Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GetRequestStream gives memory leak (BUG?)

68 views
Skip to first unread message

Thomas Phan

unread,
Jan 5, 2004, 1:27:16 PM1/5/04
to
I've the following code

HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uploadUri);
...
request.Method = "POST";
using (Stream inStream..., outStream = request.GetRequestStream())
{
...
while ((bytesRead = inStream.Read(buffer, 0, buffer.Length)) > 0)
{
outStream.Write(buffer, 0, bytesRead);
}
}

If my inStream is huge (e.g. a huge XML file), i got my memory used up very
quickly, as everything get buffered in the outStream. The outStream sends
the data out, but it doesn't clear itself (as I got the sent data on the
server -- I wrote a HttpModule on the server and the memory is normal there)

I also tried to use outStream.Flush() after each Write(), but didn't
improve. I find that the stream may clear itself only when it's closed

I commented out outStream.Write, and the memory is ok (means that the
inStream and buffer don't leak)

I also tried the asynch call, begin/endgetrequeststream, but didn't get any
gd news

I'm using NetFx 1.1, I'm not sure if this is a bug or I did something wrong,
pls advice, thx

Thomas


Feroze [MSFT]

unread,
Jan 7, 2004, 12:05:54 AM1/7/04
to
Yes, the data is buffered internally. This is used because in certain
situations,(eg redirect/auth) we might need to repost the dagta to a
different server.

You can disable this by setting AllowWriteStreamBuffering=false on the
webrequest.

--
Remove "user" from the email address to reply to the author.

This posting is provided "AS IS" with no warranties, and confers no rights

Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"Thomas Phan" <twh...@entersys.com> wrote in message
news:#LyxMm70...@TK2MSFTNGP11.phx.gbl...

Thomas Phan

unread,
Jan 7, 2004, 1:51:54 PM1/7/04
to
Thanks Feroze,

It's good to know the buffering reason, thanks.

I really need to disable the buffer, as I'm writing a Http MultiPart request
to send huge files.

However, I get an exception in the client when I call:

Stream stream = request.EndGetRequestStream(ar)

My server requires authentication. I also set:

request.AllowAutoRedirect = false;
request.PreAuthenticate = true;
request.Credentials = ...

But it doesn't work. I thought the buffering feature was not there in .NET
FX 1.0

The exception says:

An unhandled exception of type 'System.Net.WebException' occurred in
system.dll

Additional information: This request requires buffering of data for
authentication or redirection to be successful.

How may I avoid this exception, and have the buffer feature off, thanks. If
necessary, I can modify my server code using HttpModule too, thanks.

Thomas

"Feroze [MSFT]" <fer...@online.microsoft.com> wrote in message
news:O4NvuvN1...@TK2MSFTNGP09.phx.gbl...

Thomas Phan

unread,
Jan 8, 2004, 12:33:09 AM1/8/04
to
Hi Feroze,

I implemented my own Http Basic Auth on the server using HttpModule, it
works

However, the Windows Auth doesn't. Is there any setting to config, so that
the Windows Auth can work, thanks

Thomas


Feroze [MSFT]

unread,
Feb 1, 2004, 8:41:44 PM2/1/04
to
There are settings in the machine.config file to enable windows
integrated authentication. You can see the asp.net quickstarts which
are part of the framework sdk.

feroze.
===============
This posting is provided as is, without any warranties and confers no
rights.

"Thomas Phan" <twh...@entersys.com> wrote in message news:<OxpEmja1...@TK2MSFTNGP09.phx.gbl>...

0 new messages