$hold, $hold_copy_map
);
+ # KCLS: List of mapped copies that are considered active
+ # enough to keep the hold alive (below) even if we have
+ # reached the maximum target loops. Currently limited to
+ # checked out copies. Capture them here before the
+ # definition of $all_copies changes below.
+ my @active_copies = grep { $_->status == 1 } @$all_copies;
+
$all_copies = [ grep { ''.$_->circ_lib ne $pu_lib && ( $_->status == 0 || $_->status == 7 ) } @good_copies ];
my $min_prox = [ sort {$a<=>$b} keys %$prox_list ]->[0];
$current_loop++ if (!@keepers);
- if ($self->{max_loops}{$pu_lib} && $self->{max_loops}{$pu_lib} >= $current_loop) {
+ # KCLS: avoid canceling a hold that has reached max
+ # loops if any mapped copies are currently checked out.
+ # The assumption is that a checked out copy will likely
+ # be returned and usable at some point (unlike available
+ # copies that are never pulled because they are really
+ # missing, etc.).
+ if (@active_copies or (
+ $self->{max_loops}{$pu_lib} &&
+ $self->{max_loops}{$pu_lib} >= $current_loop)) {
+
# We haven't exceeded max_loops yet
my @keeper_copies;
for my $cp ( @$all_copies ) {