Skip to content

Commit ae2b908

Browse files
committed
fix: avoid cross-thread keep-alive timer access
Qt logged QObject::killTimer/startTimer warnings because query threads restarted a GUI TTimer. Restart it only from the main thread.
1 parent ecc4010 commit ae2b908

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

source/dbconnection.pas

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ TDBConnection = class(TComponent)
517517
function GetRowCount(Obj: TDBObject; ForceExact: Boolean=False): Int64; virtual;
518518
procedure ClearCache(IncludeDBObjects: Boolean);
519519
procedure FetchDbObjects(db: String; var Cache: TDBObjectList); virtual; abstract;
520+
procedure RestartKeepAliveTimer;
520521
procedure KeepAliveTimerEvent(Sender: TObject);
521522
procedure Drop(Obj: TDBObject); virtual;
522523
procedure PrefetchResults(SQL: String);
@@ -3479,9 +3480,7 @@ function TMySQLConnection.Ping(Reconnect: Boolean): Boolean;
34793480
Active := True;
34803481
end;
34813482
Result := FActive;
3482-
// Restart keep-alive timer
3483-
FKeepAliveTimer.Enabled := False;
3484-
FKeepAliveTimer.Enabled := True;
3483+
RestartKeepAliveTimer;
34853484
end;
34863485

34873486
{$IFDEF HASMSSQL}
@@ -3500,9 +3499,7 @@ function TSqlSrvConnection.Ping(Reconnect: Boolean): Boolean;
35003499
end;
35013500
end;
35023501
Result := FActive;
3503-
// Restart keep-alive timer
3504-
FKeepAliveTimer.Enabled := False;
3505-
FKeepAliveTimer.Enabled := True;
3502+
RestartKeepAliveTimer;
35063503
end;
35073504
{$ENDIF}
35083505

@@ -3538,9 +3535,7 @@ function TPGConnection.Ping(Reconnect: Boolean): Boolean;
35383535
Active := True;
35393536
end;
35403537
Result := FActive;
3541-
// Restart keep-alive timer
3542-
FKeepAliveTimer.Enabled := False;
3543-
FKeepAliveTimer.Enabled := True;
3538+
RestartKeepAliveTimer;
35443539
end;
35453540

35463541

@@ -3558,9 +3553,7 @@ function TSQLiteConnection.Ping(Reconnect: Boolean): Boolean;
35583553
end;
35593554
end;
35603555
Result := FActive;
3561-
// Restart keep-alive timer
3562-
FKeepAliveTimer.Enabled := False;
3563-
FKeepAliveTimer.Enabled := True;
3556+
RestartKeepAliveTimer;
35643557
end;
35653558

35663559

@@ -3577,6 +3570,15 @@ function TSQLiteConnection.Ping(Reconnect: Boolean): Boolean;
35773570
end;}
35783571

35793572

3573+
procedure TDBConnection.RestartKeepAliveTimer;
3574+
begin
3575+
if GetCurrentThreadID <> MainThreadID then
3576+
Exit;
3577+
FKeepAliveTimer.Enabled := False;
3578+
FKeepAliveTimer.Enabled := True;
3579+
end;
3580+
3581+
35803582
procedure TDBConnection.KeepAliveTimerEvent(Sender: TObject);
35813583
begin
35823584
// Ping server in intervals, without automatically reconnecting

0 commit comments

Comments
 (0)