Skip to content

[18][base_exception] FIX: undetected deadlock on installation with demo data - #3723

Open
florian-dacosta wants to merge 1 commit into
OCA:18.0from
akretion:18-fix-base-exception
Open

[18][base_exception] FIX: undetected deadlock on installation with demo data#3723
florian-dacosta wants to merge 1 commit into
OCA:18.0from
akretion:18-fix-base-exception

Conversation

@florian-dacosta

Copy link
Copy Markdown
Contributor

What happen is that during the installation or update of a module, the init_models set a hard lock (ACCESS EXCLUSIVE) on the tables. And during this same transaction, the demo data is loaded, which may call action_confirm on a sale order, which open a new cursor which will try a Select on the sale_order table... which is locked. So we kind of got a deadlock, but postgre won't detect it because the first lock (ACCESS EXCLUSIVE) is not waiting on the second lock

Note: Odoo already protects the installation session itself with SET SESSION lock_timeout = '15s' (odoo/modules/loading.py), but the second connection does not inherit it, which is why the hang is not turned into an error after 15 seconds.

To reproduce the issue :
create a new database this way, WITH demo data : odoo -i sale_stock,sale_exception
Odoo will hang for ever during the loading of sale_stock demo data which confirm a sale order.

I guess a similar problem could happen in because of https://github.com/OCA/sale-workflow/blob/18.0/sale_exception/models/sale_order_line.py#L63
But let's wait a fix on this one before doing it in sale_exception (and maybe purchase_exception, I did not check but probably the same).

@simahawk @grindtildeath @rousseldenis
FYI @hparfr

detect_exceptions() stores the exceptions in a separate transaction (a new
cursor/connection) so that they are kept when the ongoing transaction is
rolled back. When the registry is not ready yet (module installation or
update), the ongoing transaction holds exclusive locks on the tables it has
just modified (ALTER TABLE ...). The call to
_must_raise_exception_after_detection() made inside that new transaction then
reads the model records, and the query waits for those locks forever: the
only thread able to release them is the one waiting for them.

This happens as soon as demo data confirming a sale order is loaded during a
database initialisation with sale_exception installed (e.g. the sale_stock
demo data), making the whole database initialisation hang.

Use the current cursor in that case, as already done when running tests.
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @hparfr, @sebastienbeau,
some modules you are maintaining are being modified, check this out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants