On bug 15854 we introduced a lock on the messages table to avoid generating too many checkin digest notices. We saw on a live site a different issue recently. A patron had a checkin notice with 17 items process_message_queue ran and picked the contents of that notice for sending, but had not yet marked it sent The patron returned 10 additional items These were added to the notice in the DB process_message_queue sent the digest with the contents from the initial fetch in the while loop process message queue marked the notice as sent Result: Patron received notice of 17 items checked in DB notice had 27 and is marked sent
Yikes... that's not good.
C4/Letters.pm @@ -1038,7 +1038,7 @@ sub SendQueuedMessages { $domain_limits = Koha::Notice::Util->load_domain_limits; # (re)initialize per run while( ( my $message_object = $unsent_messages->next ) && ( !$limit || $count_messages < $limit ) ) { - my $message = $message_object->unblessed; + my $message = $message_object->get_from_storage->unblessed; What about refetching the letter at the start of the loop? It's cheap and could reduce this problem.