From ddada433c0e945528eaa03c3ba26f8b126caa7e8 Mon Sep 17 00:00:00 2001 From: Arnaud Schoonjans Date: Tue, 20 Sep 2022 12:29:10 +0200 Subject: [PATCH] Fix bug where a cascading delete of an environment causes a deadlock because it acquires a table-level lock on an incorrect database table. (Issue inmanta/inmanta-core#4834, PR #4863) # Description Fix bug where lock is acquired on the ConfigurationModel table instead of the ResourceAction table. This bug causes deadlocks. closes #4834 # Self Check: - [x] Attached issue to pull request - [x] Changelog entry - [x] Type annotations are present - [x] Code is clear and sufficiently documented - [x] No (preventable) type errors (check using make mypy or make mypy-diff) - [x] Sufficient test cases (reproduces the bug/tests the requested feature) - [x] Correct, in line with design - [ ] ~~End user documentation is included or an issue is created for end-user documentation~~ # Reviewer Checklist: - [ ] Sufficient test cases (reproduces the bug/tests the requested feature) - [ ] Code is clear and sufficiently documented - [ ] Correct, in line with design --- .../unreleased/4834-acquire-lock-on-correct-db-table.yml | 6 ++++++ src/inmanta/data/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/4834-acquire-lock-on-correct-db-table.yml diff --git a/changelogs/unreleased/4834-acquire-lock-on-correct-db-table.yml b/changelogs/unreleased/4834-acquire-lock-on-correct-db-table.yml new file mode 100644 index 0000000000..051b22bb14 --- /dev/null +++ b/changelogs/unreleased/4834-acquire-lock-on-correct-db-table.yml @@ -0,0 +1,6 @@ +--- +description: Fix bug where a cascading delete of an environment causes a deadlock because it acquires a table-level lock on an incorrect database table. +issue-nr: 4834 +issue-repo: inmanta-core +change-type: patch +destination-branches: [master, iso5] diff --git a/src/inmanta/data/__init__.py b/src/inmanta/data/__init__.py index 6586c173f7..953f74d044 100644 --- a/src/inmanta/data/__init__.py +++ b/src/inmanta/data/__init__.py @@ -5573,7 +5573,7 @@ async def delete_cascade(self) -> None: await Code.delete_all(connection=con, environment=self.environment, version=self.version) # Acquire explicit lock to avoid deadlock. See ConfigurationModel docstring - await self.lock_table(TableLockMode.SHARE, connection=con) + await ResourceAction.lock_table(TableLockMode.SHARE, connection=con) await Resource.delete_all(connection=con, environment=self.environment, model=self.version) # Delete facts when the resources in this version are the only