Resource leak in Inoke<T> method of ThreeSharpQuery class

Nov 27, 2008 at 10:12 AM
Hi,

I think there is a resource leak in the Invoke<T> method of the ThreeSharpQuery class.

If you dont wrap a new instance of HttpWebResponse in a using clause or explicitly call .close you hit the ServicePointManager.DefaultConnectionLimit and calls to httpWebRequest.GetResponse() hang (im using Vista Professional).

Before you can dispose of the response you have to read the data out of the stream so in the Invoke<T> method I have had to remove the line,

response.DataStream = httpWebResponse.GetResponseStream()

and replace it with code that copies the data from the response stream into a memory stream held privately by the Affirma.ThreeSharp.Model.Response class.

I can confirm that these changes allow me to upload many 0000's of files with connection limit of 10.  Without these changes my application hangs.

Regards,

Matt
Dec 2, 2008 at 3:22 PM
Hi Matt

I've suspected that somewhere there's a connection leak in Threesharp as I've had web applications sending IIS into a tailspin after a few hours, but a bit concerned that your solution above might be a bit of a memory hog -have you found this to be the case?

Cheers
James
Dec 3, 2008 at 8:13 AM

Hi,

I dont think so.  The Transfer class implements IDisposable and the Dispose method closes the local memory stream.  If you wrap your Response object (that derives from Transfer) in a using clause I think it will be ok.

My changes do mean that the response stream holds the response data in memory for the lifetime of the Response object.  Before it was only reading the data out of the response stream on demand.

I think there is definitley a problem with Invoke<T> not disposing of the HTTPResponse.  Not 100% sure I have correct fix.

Matt








Dec 3, 2008 at 9:31 AM
Hi Matt

Thanks for your feedback. I don't think the fix will work for me unfortunately; my application is (or rather was) piping the stream requests to response.outputsream and with a few concurrent requests would quickly run out of memory.

From my research though I can support your diagnosis - the application slowly runs out of connections when the client disconnects early (mid transfer) as the Threesharp connections remain open.

Cheers
James