From 29d849ec88f1c1ee09aa6d0ce2575746de73be1e Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 5 Jul 2017 11:28:35 -0400 Subject: [PATCH] [SIGNED OFF] Bug 18725 - Process_message_queue sends duplicate emails if message_queue is not writable. Last week, we had a database server whose disk filled, causing database writes to fail. This meant that messages in message_queue marked 'pending' were not marked as 'sent' when they were added to the postfix mail queue; messages were sent every 15 minutes (as specified in the cron job) until the disk space issues were cleared. I would suggest adding a token write to the start of process_message_queue.pl as a 'canary in the coal mine'. If the database write fails, process_message_queue should stop, because it's not safe to proceed sending emails that may not be marked 'sent'. I have no good idea on how to test this patch so this is what I've got: Test Plan: 1) Apply this patch 2) prove t/db_dependent/Letters.t Signed-off-by: Katrin Fischer --- C4/Letters.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/C4/Letters.pm b/C4/Letters.pm index de8253b..0e3ec20 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1445,8 +1445,20 @@ sub _set_message_status { my $dbh = C4::Context->dbh(); my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; my $sth = $dbh->prepare( $statement ); + + my $lock_sth = $dbh->prepare('LOCK TABLES message_queue WRITE'); + my $attempts = 0; + until ( $sth->execute() ) { + $attempts++; + die 'Unable to lock message_queue to update message status: ' . $dbh->errstr() if $attempts > 10; + sleep 1; + } + my $result = $sth->execute( $params->{'status'}, $params->{'message_id'} ); + + $dbh->do('UNLOCK TABLES'); + return $result; } -- 2.7.4