Commit 8ad45474 authored by Kyle M Hall's avatar Kyle M Hall Committed by joubu

Bug 18725: Prevent process_message_queue to send 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 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'.

Test Plan:
1) Apply this patch
2) Make the message_queue table unwriteable somehow
3) Run
4) Script should die with error
Signed-off-by: Mark Tompsett's avatarMark Tompsett <>
Signed-off-by: default avatarMarcel de Rooy <>
Signed-off-by: joubu's avatarJonathan Druart <>
parent 77853e2e
......@@ -36,6 +36,7 @@ use Koha::DateUtils;
use Koha::SMS::Providers;
use Koha::Email;
use Koha::Notice::Messages;
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
use Koha::Patrons;
......@@ -1063,6 +1064,11 @@ sub SendQueuedMessages {
my $unsent_messages = _get_unsent_messages( $which_unsent_messages );
MESSAGE: foreach my $message ( @$unsent_messages ) {
my $message_object = Koha::Notice::Messages->find( $message->{message_id} );
# If this fails the database is unwritable and we won't manage to send a message that continues to be marked 'pending'
return unless $message_object->store();
# warn Data::Dumper->Dump( [ $message ], [ 'message' ] );
warn sprintf( 'sending %s message to patron: %s',
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment