Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Jul 18, 2018 7:22 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Memory Leak with HTTPSecureSocket
PostPosted: Tue Mar 01, 2011 6:32 pm 
Offline

Joined: Thu Oct 19, 2006 2:04 pm
Posts: 17
I have a console application that accesses a web service either via a HTTPsecuresocket or a HTTPsocket. When using the secure socket I have a massive memory leak in that none of the HTTPSecureSocket instances get destroyed. The code is (as far as I can tell) identical except for one case statement.
Dim hsock as mHTTPSocket
Dim vsock as mHTTPSecureSocket


Select case processorcode
case "Standard"
hsock = new mHTTPSocket
app.PrepareSocket(hsock)
hsock.requestHeaders.AppendHeader("Content-Type","application/xml")
hsock.requestHeaders.AppendHeader("Pragma","no-cache")
hsock.requestHeaders.AppendHeader("Cache-Control","no-cache")
hsock.requestHeaders.AppendHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
hsock.port = 80
hSock.Address="www.Normal.com"
URL=app.normalsocket
hsock.SetPostContent( s,"application/xml")
s = hsock.post (URL,10)
hsock=nil
Case "Secure"
vsock = new HTTPSecureSocket
app.PrepareSecureSocket(vsock)
vsock.requestHeaders.AppendHeader("Content-Type","application/xml")
vsock.requestHeaders.AppendHeader("Pragma","no-cache")
vsock.requestHeaders.AppendHeader("Cache-Control","no-cache")
vsock.requestHeaders.AppendHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
vsock.DefaultPort=16443
vsock.Port = 16443
vsock.Address="www.secure.int"
dim f as FolderItem
f = GetFolderItem("cc500.pem")
vsock.CertificateFile =f
vsock.CertificatePassword="password"
url=app.WebAddress
vsock.SetPostContent( s,"application/xml")
s = vsock.post (URL,10)
vsock=nil
end select


my subclasses do nothing other than define a destructor method which writes a line to a log file confirming the socket has been destroyed.

When I run this (as a service application on Linux and OS X) the HTTPSocket works as expected and triggers the destructor, however, the HTTPSecureSocket is never released. This routine is called multiple times so quickly leaks quite a lot of memory. I have run the various recommended introspection code snippets to see if I have a growing number of instances - And I do when using the HTTPSecureSocket and do not when using HTTP Socket (consistent with the destructor not being triggered).

Can anyone give me some pointers as to what could be causing this problem???


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory Leak with HTTPSecureSocket
PostPosted: Wed Mar 02, 2011 12:28 pm 
Offline

Joined: Thu Oct 19, 2006 2:04 pm
Posts: 17
I have reduced the problem to a simple console application. It calls the following in the run event

Dim vsock as  mHTTPSecureSocket
Dim s as string

mems = memobjects //mems is a global property that just logs the changes in memory usage
vsock = new mHTTPSecureSocket
mems= mems+memobjects // log changes in objects
vsock.requestHeaders.AppendHeader("Content-Type","application/xml")
vsock.DefaultPort=16443
vsock.Port = 16443
vsock.Address="www.website.int"
vsock.SetPostContent( s,"application/xml")
s = vsock.post (WebAddress,10)
mems= mems+memobjects // log changes in objects
vsock=nil
mems= mems+memobjects // see if anything changes when we try and deallocate



I have one other method (memobjects) that simply counts up the number of instances of the objects and the total memory used

Dim CurMem as Double
dim s as string
Dim D as new Dictionary

for i as integer = 1 to Runtime.ObjectCount
if d.HasKey( Runtime.ObjectClass(i)) then
d.Value( Runtime.ObjectClass(i))=d.Value( Runtime.ObjectClass(i))+1
else
d.Value( Runtime.ObjectClass(i))=1
end if
next i
CurMem = Runtime.MemoryUsed/1000

for each element as string in d.keys
s = s +endofline+ element +" - "+str(d.Value(element))
next element

d= nil // release the dictionary
return format(CurMem,"###,##0.0") + " Kbytes" + EndOfLine + str( Runtime.ObjectCount) + " objects" + EndOfLine + s+EndOfLine



And below is the output. The key is the last two groups, one just before I try and deallocate the socket and one just after (which shows no change in the object count or memory). My subclass has just one method, a destructor, which logs to mems if it is called. In this case it is not called.

In production, the object count and memory grows each time I make a securesocket post.

What am I doing wrong????

Help!!!

2,306.0 Kbytes
7 objects

Array - 5
Delegate - 3
App - 3
- 3
_VariantString - 2
Dictionary - 1
2,388.0 Kbytes
14 objects

_VariantString - 10
Dictionary - 3
InternetHeaders - 2
mHttpSecureSocket - 2
Array - 4
Delegate - 2
App - 2
- 3
2,445.3 Kbytes
36 objects

_VariantString - 32
Dictionary - 3
InternetHeaders - 3
mHttpSecureSocket - 2
Array - 4
Delegate - 2
App - 2
- 2
2,445.3 Kbytes
36 objects

_VariantString - 32
Dictionary - 3
InternetHeaders - 3
mHttpSecureSocket - 2
Array - 4
Delegate - 2
App - 2
- 2


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory Leak with HTTPSecureSocket
PostPosted: Wed Mar 02, 2011 1:11 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Have you tried calling .Close on the socket? Some objects are able to live beyond their reference count (actually, the system keeps its own reference) so they can "finish" their jobs. Maybe the socket thinks it still has work to do.


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory Leak with HTTPSecureSocket
PostPosted: Wed Mar 02, 2011 1:46 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
Have you tried different versions of REAL Studio to see if the other versions have the memory leak?

What version are you using and for which OS?


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory Leak with HTTPSecureSocket
PostPosted: Wed Mar 02, 2011 4:11 pm 
Offline

Joined: Thu Oct 19, 2006 2:04 pm
Posts: 17
I am using Mac OSX 10.5.8 for development and Real Studio 2010 R 5. I have tried release 5.1 and release 4 and RealBasic 2009 R 5 and all have the same issue. Also, the issue was first noticed in the production application running on Linux.

I have changed the code to try closing the socket and then nilling it, and this does not change the object count.


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory Leak with HTTPSecureSocket
PostPosted: Sun Mar 06, 2011 3:22 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
Have you made any progress with this?

What happens if you create a new project which uses the httpsecuresocket without any of your other code?

Does the leaks still happen?


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory Leak with HTTPSecureSocket
PostPosted: Sun Mar 06, 2011 3:48 pm 
Offline

Joined: Thu Oct 19, 2006 2:04 pm
Posts: 17
I have not made any progress on this.

I have made a small project, which is just the code above in a console application (so just enough code to make a socket call and the code to support looking at memory usage). I have tried various combinations of nilling, closing, etc.

I am in the process of finalising a bug report but for some reason my licence key is being rejected by Feedback ! (Hopefully customer service will resolve this on Monday)


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory Leak with HTTPSecureSocket
PostPosted: Fri Mar 11, 2011 4:07 pm 
Offline

Joined: Sat Aug 30, 2008 2:20 pm
Posts: 90
Location: Barcelona, Spain
In my opinion this is not exactly a memory leak, but a problem with the Socket classes not destroying unused and closed sockets.

See my thread at viewtopic.php?f=2&t=37463

I arrived to having more than 2.000 "not unloaded" sockets in the socket pool.

Finally, in my application, I run an autoquit routine that every sunday unloads the program, and loads it again.


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory Leak with HTTPSecureSocket
PostPosted: Mon May 23, 2011 1:54 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
Has this problem has been fixed?

Is it a socket memory leak problem or another kind of socket problem ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory Leak with HTTPSecureSocket
PostPosted: Tue May 24, 2011 12:43 am 
Offline

Joined: Thu Oct 19, 2006 2:04 pm
Posts: 17
The problem has not been fixed. I now restart the service every few hours to make keep the memory usage reasonable. the problem seems to only exist using Secure Sockets.


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory Leak with HTTPSecureSocket
PostPosted: Tue May 24, 2011 1:02 am 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
mm_flynn wrote:
The problem has not been fixed. I now restart the service every few hours to make keep the memory usage reasonable. the problem seems to only exist using Secure Sockets.


Hi.

That won't work for me, my app needs to keep running for long periods of time.

Were you able to file that bug report about it?
Have you had any communication with REAL Software staff about it?

Do you know if GUI apps also have this problem with secure sockets?

Were you able to come up with any way other than quitting the app to stop the memory eating?

What if you reuse the same instance of the secure socket instead of creating a new one every time you need a secure socket ?

Not causing your problem but I noticed in your code you're dimming two instances of the sockets (one secure, one normal) but your case only uses one (either the secure or nonsecure socket). Why not dim the socket after the case has been selected and only when you need it?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group