ir.cron's lock is discarded by scheduled jobs performing batch transactions, wreaking havoc

Bug #1086396 reported by Florent
28
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
High
OpenERP's Framework R&D

Bug Description

Hello,

we discovered that the "mail" addon is sending some messages twice.

This is because the cron task "commits" the cursor after each message, and it releases the lock which was acquired on "ir_cron" table.

  # Try to grab an exclusive lock on the job row from within the task transaction
  "SELECT * FROM ir_cron WHERE id=%s FOR UPDATE NOWAIT"

So the same cron will be launched again without waiting the end of the previous one. and the "search" will grab some mail.messages which are already processed by the first job.

We just sent some thousands of e-mails, and we had few of them which were sent twice.

The fix should be simple: do not use the main cursor to send the e-mails.

Related branches

Florent (florent.x)
affects: openobject-server → openobject-addons
description: updated
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Thanks for the detailed description! There's indeed a problem in the way ir.cron expects to manager the transaction/cursor passed to jobs being executed, and the common need for most jobs to perform batch isolated transactions and thus commit them individually.

Perhaps ir.cron should pass yet another cursor to the jobs, one that may be safely committed without releasing the cron lock. That would avoid having to do that in every other job, and possibly forgetting about it, leading to hard-to-diagnose errors.

If you agree on that, let's move the bug report to the server project for now.

affects: openobject-addons → openobject-server
Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → High
status: New → Confirmed
summary: - the process_email_queue scheduled task sends mail twice, on mass-mailing
+ ir.cron's lock is discarded by scheduled jobs performing batch
+ transactions, wreaking havoc
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

This should be fixed at revision 4744 in 7.0 server branch (rev-id: <email address hidden>)

Thanks for reporting!

Changed in openobject-server:
milestone: none → 7.0
Changed in openobject-server:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.