Page 1 of 1

Exception in releaseimmediate

Posted: 22.10.2022, 09:35
by dcoun
With last commit in 8.0-fixes trunk I seldom get this Exception Error Stack:
Exception: 20221022 07071001 + EXC EListError {Message:"List index out of bounds (4)"} [] at 3f2c98 System.Classes.pas TList.Get (5109) System.Classes.pas TList.Get (5109) System.Classes.pas TList.Get (5109) ZDbcConnection.pas TZAbstractSingleTxnConnection.ReleaseImmediat (2245) ZDbcMySql.pas TZMySQLConnection.ReleaseImmediat (928) ZDbcStatement.pas TZAbstractStatement.ReleaseImmediat (1680) ZDbcStatement.pas TZAbstractPreparedStatement.ReleaseImmediat (3861) ZDbcMySqlStatement.pas TZAbstractMySQLPreparedStatement.ReleaseImmediat (948) ZDbcConnection.pas TZAbstractDbcConnection.ReleaseImmediat (1192) ZDbcConnection.pas TZAbstractSingleTxnConnection.ReleaseImmediat (2245) ZDbcMySql.pas TZMySQLConnection.ReleaseImmediat (928) ZDbcStatement.pas TZAbstractStatement.ReleaseImmediat (1680) ZDbcStatement.pas TZAbstractPreparedStatement.ReleaseImmediat (3861) ZDbcMySqlStatement.pas TZAbstractMySQLPreparedStatement.ReleaseImmediat (948) ZDbcConnection.pas TZAbstractDbcConnection.ReleaseImmediat (1192) ZDbcConnection.pas TZAbstractSingleTxnConnection.ReleaseImmediat (2245) ZDbcMySql.pas TZMySQLConnection.ReleaseImmediat (928) ZDbcStatement.pas TZAbstractStatement.ReleaseImmediat (1680) ZDbcStatement.pas TZAbstractPreparedStatement.ReleaseImmediat (3861) ZDbcMySqlStatement.pas TZAbstractMySQLPreparedStatement.ReleaseImmediat (948) ZDbcConnection.pas TZAbstractDbcConnection.ReleaseImmediat (1192) ZDbcConnection.pas TZAbstractSingleTxnConnection.ReleaseImmediat (2245) ZDbcMySql.pas TZMySQLConnection.ReleaseImmediat (928) ZDbcStatement.pas TZAbstractStatement.ReleaseImmediat (1680) ZDbcStatement.pas TZAbstractPreparedStatement.ReleaseImmediat (3861) ZDbcMySqlStatement.pas TZAbstractMySQLPreparedStatement.ReleaseImmediat (948)

The ZDbcConnection.pas TZAbstractSingleTxnConnection.ReleaseImmediat (2245) si:

Code: Select all

  if (fActiveTransaction <> nil) and (fActiveTransaction.QueryInterface(IImmediatelyReleasable, imm) = S_OK) and (imm <> Sender) then begin
    imm.ReleaseImmediat(Sender, AError);

Re: Exception in releaseimmediate

Posted: 25.10.2022, 11:05
by marsupilami
Hello,

I looked into this. The problem is that this line doesn't do anything with a TList - at least as far as I can see. Could you please check if Optimizations are turned off in the project settings? Sometimes this gives better stack traces.

With best regards,

Jan

Re: Exception in releaseimmediate

Posted: 25.10.2022, 20:15
by dcoun
I found the reason why this exception happens. If mariadb servers restarts or disconnects, it results to this error

Re: Exception in releaseimmediate

Posted: 26.10.2022, 08:27
by marsupilami
Yes - ReleaseImmediat is part of the handling when connections are lost. But usually we shouldn't have this problem :(

Re: Exception in releaseimmediate

Posted: 26.10.2022, 13:04
by dcoun
I will try to debug it a bit. Do you have something to propose for that?

Re: Exception in releaseimmediate

Posted: 27.10.2022, 09:04
by marsupilami
My first suggestion is disable optimizations in Delphi. This helps keeping the stack trace correct. Maybe it is worth setting up a separate application for tests and do something like this:

- Connect to MariaDB/MySQL from Zeos
- Stop MariaDB/MySQL (or just pull the network cable)
- Try to do something in Zeos

Usually this should lead to an exception telling you that the connection was lost.

Re: Exception in releaseimmediate

Posted: 27.10.2022, 09:44
by aehimself
Maybe you don't need to interrupt the network. Check if killing the session is sufficient, this would make testing a lot more easy:

https://dataedo.com/kb/query/mysql/kill-session

MySQL's current implementation of .AbortOperation is similar:

Code: Select all

function TZMySQLConnection.AbortOperation: Integer;
Var
 killquery: SQLString;
 izc: IZConnection;
Begin
  { EH untested, just prepared
  if Assigned(FPlainDriver.mariadb_cancel) then begin
    Result := FPlainDriver.mariadb_cancel(FHandle);
    FPlainDriver.mariadb_reconnect(FHandle)
  end else }begin
    // https://dev.mysql.com/doc/refman/5.7/en/mysql-kill.html
    killquery := 'KILL QUERY ' + IntToStr(FPlainDriver.mysql_thread_id(FHandle));
    izc := DriverManager.GetConnection(GetURL);
    Result := izc.CreateStatement.ExecuteUpdate(killquery);
  end;
End;