Recent

Author Topic: TMSSQLConnection Fetch Loop while DB Process dead  (Read 2507 times)

Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
TMSSQLConnection Fetch Loop while DB Process dead
« on: October 06, 2017, 12:38:41 pm »
Hi All, I am new here

currently I m working on mssql database for logging using Linux freetds, sqldb.
Some how I got error when querying large data set
when network error or connection is kill, the process become almost 100% and app doesnt quit  :o 
 
so trace to this code I found that dbnextrow return 0 which equal FAIL
but in this code no handling for exit

function TMSSQLConnection.Fetch(cursor: TSQLCursor): boolean;
begin
  // Compute rows resulting from the COMPUTE clause are not processed
  repeat
    Fstatus := dbnextrow(FDBProc);
    Result  := Fstatus=REG_ROW;
  until Result or (Fstatus = NO_MORE_ROWS);   /// this make loop forever

  if Fstatus = NO_MORE_ROWS then
    while dbresults(FDBProc) <> NO_MORE_RESULTS do // process remaining results if there are any
      repeat until dbnextrow(FDBProc) = NO_MORE_ROWS;
end;

because I new here dunno how to make it fix or anybody could check it too?

my current fixed is this

function TMSSQLConnection.Fetch(cursor: TSQLCursor): Boolean;
   begin
      // Compute rows resulting from the COMPUTE clause are not processed
      repeat     
         Fstatus := dbnextrow(FDBProc);
         Result  := Fstatus = REG_ROW;
      until Result or (Fstatus = NO_MORE_ROWS)
            or (FStatus = FAIL);

      if Fstatus = NO_MORE_ROWS then
         while dbresults(FDBProc) <> NO_MORE_RESULTS do // process remaining results if there are any
            repeat
               FStatus := dbnextrow(FDBProc);
            until (FStatus = NO_MORE_ROWS) or (FStatus = FAIL); 

      if FStatus = FAIL then
         CheckError( dbresults(FDBProc) );

   end;

probably not best fix


LacaK

  • Hero Member
  • *****
  • Posts: 605
Re: TMSSQLConnection Fetch Loop while DB Process dead
« Reply #1 on: October 08, 2017, 10:53:11 am »
Yes, it seems, that FAIL is not handled in case when DB Process becomes dead ... I will improve it after testing ... I will let you know
I added a bug report: https://bugs.freepascal.org/view.php?id=32524

Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Re: TMSSQLConnection Fetch Loop while DB Process dead
« Reply #2 on: October 09, 2017, 10:49:47 am »
almost forgot  also in TMSSQLConnection.Execute

         if not c.FSelectable then  //Sybase stored proc.
         begin
            repeat until dbnextrow(FDBProc) = NO_MORE_ROWS;
            res := CheckError( dbresults(FDBProc) );
            // stored procedure information (return status and output parameters)
            // are available only after normal results are processed
            //if res = NO_MORE_RESULTS then GetParameters(cursor, AParams);
         end;


Thanks in advance

LacaK

  • Hero Member
  • *****
  • Posts: 605
Re: TMSSQLConnection Fetch Loop while DB Process dead
« Reply #3 on: October 27, 2017, 02:02:11 pm »
I am trying to simulate problem.
Strange thing is that I can not reproduce described behavior.
I read rows from large table in loop and while reading I unplug network cable to simulate network failure.
Loop stop reading, but no error is returned. Instead application freezes in call to dbnextrow() in dblib.dll (libsybdb.so). So it freezes not in loop in TMSSQLConnection.Fetch but somewhere in freetds library ...
Same on Windows and Linux.

LacaK

  • Hero Member
  • *****
  • Posts: 605
Re: TMSSQLConnection Fetch Loop while DB Process dead
« Reply #4 on: October 31, 2017, 10:03:05 am »
Fixed in TRUNK

 

TinyPortal © 2005-2018