🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #2682

Re: TCPServer Out of memory exception

#2682
From: Remy Lebeau (TeamB)
Date: Mon, 06 Feb 2006 22:03
38 lines
2549 bytes
Raffaele Pantaleoni <pantaraf@yahoo.it> wrote:

>    Msg=AThread->Connection->ReadLn("",5);

You did not specify any terminator.  Indy will use LF by default.  If the client sends lots of data without sending LF then you could be filling up memory.

Also, you specified a 5-millisecond timeout, but are not using the ReadLnTimedOut property afterwards.  Indy is best used when you let its operations block without timeouts, especially when using any of Indy's multithreaded components  Use timeouts only when you actually need to, and know how to handle them.

>  catch (Exception &exception)

If an Indy exception occurs (one that is derived from EIdException), you should re-throw the exception so that the server knows that something went wrong with the connection.  If you do not do that, or if you do not disconnect the connection manually, then the thread will never terminate properly.

For example:

    void __fastcall TForm1::tcpServerExecute(TIdPeerThread *AThread)
    {
        AnsiString Msg;
        try
        {
            Msg = AThread->Connection->ReadLn();
        }
        catch(const Exception &exception)
        {
            ExceptionsLog("tcpServerExecute", exception.Message);
            if( exception->InheritsFrom(__classid(EIdException)) )
                throw;
        }
    }

> The system memory is still avalaible when the error
> come out, and the process itself hasn't growth in
> memory size.

When the VCL runtime is allocating a string, a memory exception can be thrown without any actual memory actually being allocated if the runtime can determine ahead of time that the new string length is too large for memory to satisfy.


Gambit
Technical Details
Message-ID: <43e7d5c9$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news3.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <43e71eee$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,bcfef8d7a8434913
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau (TeamB)" <no.spam@no.spam.com>
Sender: "Remy Lebeau (TeamB)" <no.spam@no.spam.com>
Reply-To: "Remy Lebeau (TeamB)" <no.spam@no.spam.com>
Subject: Re: TCPServer Out of memory exception
Newsgroups: borland.public.cppbuilder.internet.socket
X-User-Info: 69.175.11.30     
References:  <43e71eee$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <43e7d5c9$1@newsgroups.borland.com>
Date: 6 Feb 2006 15:03:37 -0700
X-Trace: newsgroups.borland.com 1139267017 207.105.83.66 (6 Feb 2006 15:03:37 -0700)
Lines: 38
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news3.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail