Discussion:
Leak in HTTPRio? in TOMCAT? No more Internet handles can be allocated
(too old to reply)
m***@bo.nettuno.it
2007-10-05 13:43:20 UTC
Permalink
Hello,
sorry for crossposting but I think it involves all the 3 groups.
I have a server application that communicate with many clients via
TCP/IP sockets.

void __fastcall TForm1::IdTCPServer1Execute(TIdPeerThread *AThread)
each TCPServer1Execute thread launched by a request from a client
generates a call to an external webservice with this procedure:

THTTPRIO* iRio = new THTTPRIO(this);
iRio->URL = "urlname";
_di_Server iService;
iRio->QueryInterface(iService);

Response=iService->serviceName(XMLDocument->XML->Text);
iService = NULL;

It works perfectly for days, then suddendly it crashes every
webservice call with a:
"No more Internet handles can be allocated - URL:urlname -
SOAPAction:"""

where urlname is the same valid URL I use in the program.
The web service server is TOMCAT, and the same happens on different
servers where the two applications are installed.

Do you have any idea of why this is happening?

Thanks!
Matt
Remy Lebeau (TeamB)
2007-10-05 16:54:33 UTC
Permalink
Post by m***@bo.nettuno.it
THTTPRIO* iRio = new THTTPRIO(this);
Are you ever deleting that object after sending a request?

Assuming 'this' is the pointer to your TForm1 instance, I do not suggest
using the TForm as the Owner for the object. TIdTCPServer is a
multi-threaded component, and the TForm's Components array is not
thread-safe. Use a NULL Owner and 'delete' the object when you are done
with it, ie:

THTTPRIO* iRio = new THTTPRIO(NULL);
//...
delete iRio;


Gambit
m***@bo.nettuno.it
2007-10-08 08:53:31 UTC
Permalink
Hello,

if I delete the iRio, I receive an AccessViolation error.
I changed the 'this' to 'NULL' anyway, but I still don't know if
that's was the problem because it normally occurs after some days.

THTTPRIO* iRio = new THTTPRIO(NULL);
//...
delete iRio;

Do you have any idea why I receive this AccessViolation?

Thanks,
Mattia
Post by Remy Lebeau (TeamB)
Post by m***@bo.nettuno.it
THTTPRIO* iRio = new THTTPRIO(this);
Are you ever deleting that object after sending a request?
Assuming 'this' is the pointer to your TForm1 instance, I do not suggest
using the TForm as the Owner for the object. TIdTCPServer is a
multi-threaded component, and the TForm's Components array is not
thread-safe. Use a NULL Owner and 'delete' the object when you are done
THTTPRIO* iRio = new THTTPRIO(NULL);
//...
delete iRio;
Gambit
Jean-Marie Babet
2007-10-11 23:20:10 UTC
Permalink
Hello Mattia,
Post by m***@bo.nettuno.it
if I delete the iRio, I receive an AccessViolation error.
The most common reason why deleting a RIO causes an AV is if it was created
with (NULL). When you create a RIO object with NULL, its lifetime will be
managed via the refcount of the interface it hands out. So you do *NOT* want
to call delete on the object explicitly. You simply want to release the
interface it handed out.

To illustrate:

THTTPRIO* iRIO = new THTTPRIO(NULL);

__di_someInterface service;
iRIO->QueryInterface(service);

service.Release(); // < (**)


The call to 'service.Release()' will cleanup the iRIO instance (provided no
one else is holding on to references to 'service').

Let me know if the above does not help!

Cheers,

Bruneau.
m***@bo.nettuno.it
2007-10-15 15:18:35 UTC
Permalink
Hello Jean Marie,
Post by Jean-Marie Babet
service.Release(); // < (**)
previous than deleting iRio, and following some other samples, I used:
service = NULL;
that doesn't give the AV and works, but as reported earlier, after
some time (can be just some days or weeks) suddendly it crashes every
webservice call with a:
"No more Internet handles can be allocated - URL:urlname -
SOAPAction:"""

I'll change service=NULL to service.Release(); as per you
reccomendation, but do you think it will behave differently in the
long time? (I mean: do you think that using the NULL assignment was
wrong and was the cause of the "No more internet handles...")

Thank you very much!
Mattia
Post by Jean-Marie Babet
The call to 'service.Release()' will cleanup the iRIO instance (provided no
one else is holding on to references to 'service').
Let me know if the above does not help!
Cheers,
Bruneau.
Jean-Marie Babet
2007-10-15 19:01:09 UTC
Permalink
Hello,

Invoking Release() or assigning NULL to a DelphiInterface<T> should have the
same effect: i.e. invoke 'Release' on the underlying interface.

What version of Delphi do you have? I don't recall any particular issue in
that area but it's possible that maybe the version of the runtime you're
using had a leak of interface handles.

Cheers,

Bruneau.
m***@bo.nettuno.it
2007-10-15 22:31:24 UTC
Permalink
Hello,

not Delphi, I'm using CBuilder 6.
Actually, looking for "httprio leak" in google I found some references
to a similar problem (many users are experiencing a memory leak using
the component) but I couldn't find a way to solve it.
And I don't know if I'm having the same problem (I notice the memory
leak using the memproof program), but I don't know if the same memory
leak is responsible of the strange error message I receive:
"No more Internet handles can be allocated - URL:urlname -
SOAPAction:"""

Thanks,
Mattia
Post by m***@bo.nettuno.it
Hello,
Invoking Release() or assigning NULL to a DelphiInterface<T> should have the
same effect: i.e. invoke 'Release' on the underlying interface.
What version of Delphi do you have? I don't recall any particular issue in
that area but it's possible that maybe the version of the runtime you're
using had a leak of interface handles.
Cheers,
Bruneau.
Jean-Marie Babet
2007-10-16 17:00:35 UTC
Permalink
Hello,
Post by m***@bo.nettuno.it
not Delphi, I'm using CBuilder 6.
OK! Yes, if it's CBuilder6 you're probably running into a runtime bug that
has been addressed. Unfortunately, it's not that easy to merge the current
runtime to the v6.0 version. Let me see if I can find any change that would
be relevant to this issue. If time allows, can you email me a copy of the
SOAPHTTPTrans.pas file from your copy of CBuilder6.

Cheers,

Bruneau.
m***@bo.nettuno.it
2007-10-17 09:42:10 UTC
Permalink
Post by Jean-Marie Babet
OK! Yes, if it's CBuilder6 you're probably running into a runtime bug that
Oh great, I just sent the files to your email.
Thank you very much for your help.
Mattia

Loading...