[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:
Christophe Simonis
2022-06-18 11:20:29 +02:00
parent dc66b7aec3
commit 03c954b5b0
+5 -3
View File
@@ -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):