Bugzilla – Attachment 61422 Details for
Bug 15854
Race condition for sending renewal/check-in notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15854: Use a READ and WRITE LOCK on message_queue
Bug-15854-Use-a-READ-and-WRITE-LOCK-on-messagequeu.patch (text/plain), 2.49 KB, created by
Martin Renvoize
on 2017-03-21 19:53:41 UTC
(
hide
)
Description:
Bug 15854: Use a READ and WRITE LOCK on message_queue
Filename:
MIME Type:
Creator:
Martin Renvoize
Created:
2017-03-21 19:53:41 UTC
Size:
2.49 KB
patch
obsolete
>From 6e4c1acfd7a5de138278037e6d60eb97d6921412 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 9 Feb 2017 12:44:38 +0100 >Subject: [PATCH] Bug 15854: Use a READ and WRITE LOCK on message_queue >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >To make sure we will not never get a race conditions for these kinds of >notices, we need to add a LOCK on the message_queue table. > >This does not smell the best way to do that, but I faced deadlock issues >when I tried to use "UPDATE FOR" > >https://dev.mysql.com/doc/refman/5.7/en/innodb-locking-reads.html >https://dev.mysql.com/doc/refman/5.7/en/lock-tables.html >https://dev.mysql.com/doc/refman/5.7/en/commit.html > >To test this patch, or another solution, you need to apply manually this >change: > > my $message = C4::Message->find_last_message($borrower, $type, $mtt); > unless ( $message ) { >+ sleep(1); > C4::Message->enqueue($letter, $borrower, $mtt); > } else { > >And repeat the test plan from first patch. >Do not forget to truncate the message_queue table. > >Followed test plans, works as expected. >Signed-off-by: Marc Véron <veron@veron.ch> > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > C4/Circulation.pm | 7 +++++++ > 1 file changed, 7 insertions(+) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 5dea088..34e2719 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -3323,6 +3323,7 @@ sub SendCirculationAlert { > }); > my $issues_table = ( $type eq 'CHECKOUT' || $type eq 'RENEWAL' ) ? 'issues' : 'old_issues'; > >+ my $schema = Koha::Database->new->schema; > my @transports = keys %{ $borrower_preferences->{transports} }; > for my $mtt (@transports) { > my $letter = C4::Letters::GetPreparedLetter ( >@@ -3340,13 +3341,19 @@ sub SendCirculationAlert { > } > ) or next; > >+ $schema->storage->txn_begin; >+ C4::Context->dbh->do(q|LOCK TABLE message_queue READ|); >+ C4::Context->dbh->do(q|LOCK TABLE message_queue WRITE|); > my $message = C4::Message->find_last_message($borrower, $type, $mtt); > unless ( $message ) { >+ C4::Context->dbh->do(q|UNLOCK TABLES|); > C4::Message->enqueue($letter, $borrower, $mtt); > } else { > $message->append($letter); > $message->update; > } >+ C4::Context->dbh->do(q|UNLOCK TABLES|); >+ $schema->storage->txn_commit; > } > > return; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15854
:
60057
|
60058
|
60813
|
60814
|
61421
| 61422