Really strange terminating bug.

Help
2003-07-04
2004-03-24
  • Nobody/Anonymous

    Hi,

    my software is kylix console application running Direct SQL unit. Every now and then it sends a line or two to a mySql server. The problem is, when it has been idle for a longer moment (over night, when there is no activity) and after which it to send a packet (at mornings) the whole console application mysteriously terminates.

    Its very strange. I searched the direct Sql sourcecode for application terminating code, but i didn't find any. All exceptions are catched. There is no error message, no exception, no nothing, the application just terminates.

    i've isolated the termination to this instruction:
      SqlResult := mySql.query(Str,true,result);

    the whole code around it looks like

    if sql<>nil then
        Try
            write('Sending sql .. ');
            SqlResult := mySql.query(Str,true,result);
            writeln('done');
        Except
          on E:Exception do
            Writeln('Error on sending SQL info '+E.classname+' '+E.message);
        end;

    Normally when i run this there is no problem. The logs show 'sending sql .. done' . But in the mornings the whole application has been terminated with out any reasonable reason. And the last incomplete line in the log is 'sending sql .. '.

    Someone suggested that the application reserves too much system resources and the kernel terminates it.

     
    • Jeremy Darling

      Jeremy Darling - 2003-07-07

      A few obvious questions to get started off.  Are you sure that you machine isn't rebooting itself in some type of nightly process, this may even be caused by a remote system.  Or that you don't have another piece of software that is closing down your program.  If the answer to both of these if No then you have a problem down in the bowles that is causing a system level error.  These won't be caught by your code and will cause the app to just "Die".  You might try checking to make sure that the connection is still valid and that you have auto reconnect set to true as MySQL will kill a Dead Link if it thinks it has one thus causing your connection to be invalid and causing the error I was just talking about.  Create a last executed variable and check it before you run your query if its over say 4 hrs then try reconnecting (I've seen times when the library does think its connected but its not).

      If nothing helps send more info and I'll see what I can find in my bag of tricks.

       
    • Nobody/Anonymous

      I found out the bug and fixed it.
      I got on the right track when i noticed that there were tens of thousands open socket handles with lsof command. The mysql-component didn't close the sockets.

      In method TMysqlVio.vio_close in uMysqlVio.pas the socket

      The socket closing code looks like this:
                    {$IFDEF _WIN_}
                    if (closesocket(fsd)<>0) then
                       result:=-1;
                    {$ELSE}
                    {$ENDIF}
      So it does nothing with kylix :(

      I fixed it by adding regular close to imports on line 317:
      function closesocket(handle: longint): Integer; cdecl;external 'libc.so.6' name 'close';

      and

      changed TMysqlVio.vio_close to look like this
                    {$IFDEF _WIN_}
                    if (closesocket(fsd)<>0) then
                       result:=-1;
                    {$ELSE}
                    if (closesocket(fsd)<>0) then
                       result:=-1;
                    {$ENDIF}

      the same source is available at http://130.233.27.108/uMysqlVio.pas

       
    • Nobody/Anonymous

      Thank you very much for your time in tracking down this problem ..
      I will make sure it would be included in 1.1.4 :D

      Regards,
      Cristian Nicola

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks