Skip to content

Commit eae701f

Browse files
committed
fix: stop closing pooled MySQL connections
AccountingDB.insertRecordDirectly, DirectoryTreeBase.getDirectorySize and PilotStatusAgent.execute all called .close() on a connection obtained from the per-thread pool, destroying the pooled socket while the pool's __assigned dict still cached the reference. Stock code masked this with the per-call ping that reconnected on the next checkout; once the warm ping skip was deployed the dead reference was reused inside the idle window and the next query failed with (2006, '').
1 parent 4c6d73c commit eae701f

3 files changed

Lines changed: 15 additions & 24 deletions

File tree

src/DIRAC/AccountingSystem/DB/AccountingDB.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -632,24 +632,21 @@ def insertRecordDirectly(self, typeName, startTime, endTime, valuesList):
632632
if not retVal["OK"]:
633633
return retVal
634634
connObj = retVal["Value"]
635-
try:
636-
retVal = self.insertFields(
637-
_getTableName("type", typeName), self.dbCatalog[typeName]["typeFields"], insertList, conn=connObj
638-
)
639-
if not retVal["OK"]:
640-
return retVal
641-
# HACK: One more record to split in the buckets to be able to count total entries
642-
valuesList.append(1)
643-
retVal = self.__startTransaction(connObj)
644-
if not retVal["OK"]:
645-
return retVal
646-
retVal = self.__splitInBuckets(typeName, startTime, endTime, valuesList, connObj=connObj)
647-
if not retVal["OK"]:
648-
self.__rollbackTransaction(connObj)
649-
return retVal
650-
return self.__commitTransaction(connObj)
651-
finally:
652-
connObj.close()
635+
retVal = self.insertFields(
636+
_getTableName("type", typeName), self.dbCatalog[typeName]["typeFields"], insertList, conn=connObj
637+
)
638+
if not retVal["OK"]:
639+
return retVal
640+
# HACK: One more record to split in the buckets to be able to count total entries
641+
valuesList.append(1)
642+
retVal = self.__startTransaction(connObj)
643+
if not retVal["OK"]:
644+
return retVal
645+
retVal = self.__splitInBuckets(typeName, startTime, endTime, valuesList, connObj=connObj)
646+
if not retVal["OK"]:
647+
self.__rollbackTransaction(connObj)
648+
return retVal
649+
return self.__commitTransaction(connObj)
653650

654651
def deleteRecord(self, typeName, startTime, endTime, valuesList):
655652
"""

src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/DirectoryManager/DirectoryTreeBase.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,12 +804,10 @@ def getDirectorySize(self, lfns, longOutput=False, rawFileTables=False, recursiv
804804
)
805805

806806
if not resultLogical["OK"]:
807-
connection.close()
808807
return resultLogical
809808

810809
resultDict = resultLogical["Value"]
811810
if not resultDict["Successful"]:
812-
connection.close()
813811
return resultLogical
814812

815813
if longOutput:
@@ -826,11 +824,9 @@ def getDirectorySize(self, lfns, longOutput=False, rawFileTables=False, recursiv
826824
resultDict["QueryTime"] = time.time() - start
827825
result = S_OK(resultDict)
828826
result["Message"] = "Failed to get the physical size on storage"
829-
connection.close()
830827
return result
831828
for lfn in resultPhysical["Value"]["Successful"]:
832829
resultDict["Successful"][lfn]["PhysicalSize"] = resultPhysical["Value"]["Successful"][lfn]
833-
connection.close()
834830
resultDict["QueryTime"] = time.time() - start
835831

836832
return S_OK(resultDict)

src/DIRAC/WorkloadManagementSystem/Agent/PilotStatusAgent.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ def execute(self):
6868
# Now handle pilots not updated in the last N days and declare them Deleted.
6969
result = self.handleOldPilots(connection)
7070

71-
connection.close()
72-
7371
result = self.pilots.clearPilots(self.clearPilotsDelay, self.clearAbortedDelay)
7472
if not result["OK"]:
7573
self.log.warn("Failed to clear old pilots in the PilotAgentsDB")

0 commit comments

Comments
 (0)