https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=35734

--- Comment #2 from Adolfo Rodríguez Taboada <[email protected]> ---
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.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to