[FIX] core: always close cursors at the exit of context managers
The call to `commit()` can fail during the flush of the environment and raise an exception before the actual `COMMIT;`, leaving the cursor unclosed. This leaked cursor may hold locks that only be released when the GC collects it. On low-traffic workers like the CronWorker, this can lock usual database usages. X-original-commit: 3cb3cec67c28ca147288103adb219e6da8694248 Part-of: odoo/odoo#93993
This commit is contained in:
+5
-3
@@ -198,9 +198,11 @@ class BaseCursor:
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
if exc_type is None:
|
||||
self.commit()
|
||||
self.close()
|
||||
try:
|
||||
if exc_type is None:
|
||||
self.commit()
|
||||
finally:
|
||||
self.close()
|
||||
|
||||
|
||||
class Cursor(BaseCursor):
|
||||
|
||||
Reference in New Issue
Block a user