Browse Source

pqconnection: commit/rollback - protect the TPGHandle.Used change with...

Ondrej Pokorny 2 weeks ago
parent
commit
1488858efb
1 changed files with 12 additions and 2 deletions
  1. 12 2
      packages/fcl-db/src/sqldb/postgres/pqconnection.pp

+ 12 - 2
packages/fcl-db/src/sqldb/postgres/pqconnection.pp

@@ -605,8 +605,13 @@ var
 
 begin
   tr := (trans as TPQTransactionHandle).Handle as TPGHandle;
-  tr.Used:=False; // handle can be reused after rollback (even if it failed)
   TR.RollBack;
+  FHandlePool.LockList; // protect the Used change with critical section
+  try
+    tr.Used:=False; // handle can be reused after successful rollback
+  finally
+    FHandlePool.UnLockList;
+  end;
   result := true;
 end;
 
@@ -616,7 +621,12 @@ var
 begin
   tr := (trans as TPQTransactionHandle).Handle;
   tr.Commit;
-  tr.Used:=False; // handle can be reused after successful commit
+  FHandlePool.LockList; // protect the Used change with critical section
+  try
+    tr.Used:=False; // handle can be reused after successful commit
+  finally
+    FHandlePool.UnLockList;
+  end;
   Result:=True;
 end;