[Bug 35734] New: Message queue table lock will crash Koha
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=35734 Bug ID: 35734 Summary: Message queue table lock will crash Koha Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Circulation Assignee: koha-bugs@lists.koha-community.org Reporter: johanna.raisa@koha-suomi.fi QA Contact: testopia@bugs.koha-community.org CC: gmcharlt@gmail.com, kyle.m.hall@gmail.com Locking the message_queue table on circulation and reserves will crash Koha, if there are many circulation or/and reservation operations on running and the process_message_queue cron is processing messages. Locking a table is not a very good way to handle digest messages and active queue, this should be handled with a new message status instead. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=35734 --- Comment #1 from Johanna Räisä <johanna.raisa@koha-suomi.fi> --- I investigated this problem further, seems that the issue appears when there are lot of rows in the message_queue table. One of our biggest Koha had last year 1892573 message rows and it takes a while finding messages with pending status. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=35734 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff Assignee|koha-bugs@lists.koha-commun |adolfo.rodriguez@xercode.es |ity.org | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=35734 --- Comment #2 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Created attachment 212256 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212256&action=edit Bug 35734: Do not lock the whole message_queue table when queuing digest notices SendCirculationAlert and _koha_notify_reserve append the notice to the pending message of the patron (digests) inside a LOCK TABLE message_queue READ/WRITE ... UNLOCK TABLES block: - If anything dies inside the block, UNLOCK TABLES is never run and the table stays locked on that database connection. Every request that needs message_queue waits on it, and with persistent connections (Plack) the whole instance can hang. - Even when nothing fails, the lock serializes the notices of all the patrons, on every checkout, checkin, renewal and hold. - It does not even prevent the race it is meant to prevent: when there is no pending message, the table is unlocked before the new message is enqueued, so two concurrent requests can enqueue two messages. - LOCK TABLES commits the current transaction, so the code has to guess whether it runs from the tests ($ENV{_} =~ /prove/ or KOHA_TESTING). This patch moves the block to a new method, C4::Message->enqueue_or_append. It locks the row of the patron (SELECT ... FOR UPDATE) inside a transaction: only the requests for the same patron wait for each other, the lock is released when the transaction ends, and a failure is rolled back. If the notice cannot be queued, the error is logged and the checkout, checkin or hold goes on. Test plan: 1. Apply the patch 2. Run: $ prove t/db_dependent/Message.t t/db_dependent/Circulation.t t/db_dependent/Reserves.t => SUCCESS: Tests pass! 3. Enable EnhancedMessagingPreferences, and make sure there are email templates for the CHECKOUT and CHECKIN notices (Circulation module) and for the HOLDDGST notice (Holds module) 4. Choose a patron with an email address and, in their messaging preferences, select Email for Item checkout and Item check-in, and Email and Digests only for Hold filled 5. Check out two items to the patron, then check them in 6. Go to the Notices tab of the patron => There is a single pending CHECKOUT notice that lists both items, and a single pending CHECKIN notice that lists both items 7. Place holds for the patron on two records and check in an item of each one, confirming the holds => There is a single pending HOLDDGST notice that lists both holds 8. Sign off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=35734 --- Comment #3 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- We hit this in production: an unrelated exception was raised inside the LOCK TABLE message_queue ... UNLOCK TABLES block of SendCirculationAlert, so UNLOCK TABLES never ran. With persistent connections (Plack), the table stayed locked on that worker's connection, every request that touched message_queue waited on it, and the staff interface and the OPAC went down. The same block is in C4::Reserves::_koha_notify_reserve (hold digests). The attached patch moves the block to a new method, C4::Message->enqueue_or_append, that locks the row of the patron (SELECT ... FOR UPDATE) in a transaction instead of the whole table: - Only concurrent notices for the same patron wait for each other. - The lock is released when the transaction ends, whatever happens; a failure is rolled back (to a savepoint if there is an enclosing transaction). - If the notice cannot be queued, the error is logged and the checkout, checkin or hold goes on. - The current lock does not even prevent the race it is meant for: when there is no pending message, the table is unlocked before the new message is enqueued. With the row lock, the enqueue is protected too. - The code no longer needs to guess whether it runs from the tests ($ENV{_} =~ /prove/ or KOHA_TESTING). Note: koha-qa reports a pod_coverage failure on C4/Message.pm for subs that already had no POD (AUTOLOAD, DESTROY, _metadata, _to_address); the patch does not add any. Bug 37548 is a different race (between the digest and process_message_queue), not addressed here. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=35734 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=15854, | |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=37548 -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org