https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43989 --- Comment #3 from Sam Young <sam.young@bywatersolutions.com> --- Bug 43989: Prevent concurrent holds queue updates from dropping holds When two holds queue updates for the same record run at the same time, one can fail with a deadlock and is never retried, so the hold stays off the Holds queue. This locks the record while its queue entries are rebuilt, so updates run one after the other, and retries an update that hits a deadlock. To test: 1. Before applying the patch, save the script below as /tmp/race.pl 2. Run: cd /kohadevbox/koha && perl -I. /tmp/race.pl 3. Observe that Update 2 fails with "Deadlock found when trying to get lock" 4. Apply patch 5. restart_all 6. Run: cd /kohadevbox/koha && perl -I. /tmp/race.pl 7. Observe that both Update 1 and Update 2 are OK 8. prove t/db_dependent/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.t 9. Observe that all tests pass The script creates a record with one item and a hold, then runs two holds queue updates for it at the same time: use Modern::Perl; use t::lib::TestBuilder; use C4::HoldsQueue; use C4::Reserves qw(AddReserve); use Koha::Database; my $builder = t::lib::TestBuilder->new; my $item = $builder->build_sample_item; my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $item->homebranch } } ); AddReserve( { branchcode => $item->homebranch, borrowernumber => $patron->id, biblionumber => $item->biblionumber, priority => 1 } ); # Widen the window between the DELETE and the INSERTs no warnings 'redefine'; my $orig = \&C4::HoldsQueue::CreatePicklistFromItemMap; *C4::HoldsQueue::CreatePicklistFromItemMap = sub { sleep 2; $orig->(@_) }; for my $n ( 1 .. 2 ) { next if fork; Koha::Database->schema->storage->_dbh->{InactiveDestroy} = 1; Koha::Database->schema->storage->disconnect; sleep $n; my $storage = Koha::Database->schema->storage; eval { $storage->txn_begin; C4::HoldsQueue::update_queue_for_biblio( { biblio_id => $item->biblionumber, delete => 1 } ); $storage->txn_commit; say "Update $n: OK"; 1; } or do { $storage->txn_rollback; say "Update $n: FAILED - " . ( $@ =~ /(Deadlock found[^;]*)/ ? $1 : $@ ); }; exit; } wait for 1 .. 2; $item->biblio->delete; $patron->delete; -- You are receiving this mail because: You are watching all bug changes.