fix(plugin-multi-tenant): run tenant delete cleanup inside the request transaction#17045
Open
yashs33244 wants to merge 1 commit into
Open
fix(plugin-multi-tenant): run tenant delete cleanup inside the request transaction#17045yashs33244 wants to merge 1 commit into
yashs33244 wants to merge 1 commit into
Conversation
DanRibbens
approved these changes
Jun 18, 2026
Contributor
|
As a heads up, the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Deleting a tenant hangs forever (on Postgres) when the multi-tenant plugin has one or more collections marked
isGlobal: true. The request never resolves and no error is thrown.Fixes #16045
Why?
The tenants collection
afterDeletehook (afterTenantDelete) cleans up tenant-scoped docs by callingpayload.delete/find/updatewithout passingreq. Withoutreq, each of those operations opens its own database transaction.That cleanup runs while the parent tenant-delete transaction is still open and holding row locks. A global collection has a
uniquetenant field that FK-references the tenant row being deleted, so its cleanup delete needs a lock the parent transaction holds. The cleanup's separate transaction waits on the parent, and the parent waits for the hook to return - a cross-transaction deadlock across two pooled connections that Postgres can't detect, so it hangs indefinitely. SQLite happens to tolerate it, which is why it only reproduces on Postgres.How?
Pass
reqto the cleanupdelete,find, andupdatecalls so they join the existing request transaction instead of opening new ones. This matches how other plugins (e.g.plugin-search'sdeleteFromSearch) propagate the transaction in theirafterDeletehooks, and makes the cleanup atomic with the tenant delete.Added an integration test that creates a tenant with a global-collection document and asserts the delete completes. It times out (hangs) without the fix and passes with it. Verified against Postgres and SQLite (
pnpm test:int:postgres plugin-multi-tenant,pnpm test:int:sqlite plugin-multi-tenant).