mirror of
https://github.com/xcat2/xcat-dep.git
synced 2026-11-30 06:12:16 +00:00
fix(nfslock): a dead owner does not mean the work it started has stopped
The ownership identity is one process, and what a lock protects outlives it. A build wrapper starts each command in its own process group, so SIGKILL on the wrapper leaves that group running. acquire proved the owner dead and took the lock, and two builds then wrote one checkout. The build wrapper's own cancellation path keeps the lock when a group survives cleanup, and this recovery undid that retention: it read a dead owner and took the lock the retention had kept. A holder now ATTACHES each process group it starts and DETACHES it once the group is gone. attach records lock.d/workers/<pgid>.<leader pstart>. An owner is recoverable only when it is provably dead AND every attached group is gone, so the retention is a fact recovery reads rather than a directory it has to guess about. A group is gone only when kill(0, -pgid) answers ESRCH, which is the test the cancellation path already uses before it releases. The two now agree. Reaping the LEADER is not enough, because its children inherit the group, so the test is on the group and not on the leader's pid. detach applies the same test and refuses while any process is in the group. Reuse windows. The entry name carries the leader's start time, so removing a record by name cannot remove that of a later group which reused the pgid. The group test itself cannot tell a recycled pgid from the original group and reads live for both, which costs a wait rather than admitting a second writer. Neither can tell a worker that left its group by calling setpgid itself; the cancellation path has the same limit, and the two agree. An exclusive claim on the root does not override a live group. The claim asserts no build is running, and a live group is evidence that one is. release drops the records of groups that are gone and keeps the rest, so a worker killed before its reap cannot make a lock unreleasable, and a live one stops the release because rmdir refuses a non-empty directory. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
@@ -268,6 +268,9 @@ sub acquire {
|
||||
my $again = _read_metadata($abs);
|
||||
return 0 unless defined($again) && _key($again) eq _key($observed);
|
||||
return 0 unless owner_is_dead($again, $here);
|
||||
# The owner is dead. The work it started may not be.
|
||||
my @live = live_workers($abs);
|
||||
if (@live) { $workers = $live[0]{pgid}; return 0 }
|
||||
my $mine = this_process();
|
||||
_at('before-commit');
|
||||
_write_metadata($abs, $mine);
|
||||
@@ -721,6 +724,7 @@ sub attach {
|
||||
sub detach {
|
||||
my ($self, $pgid) = @_;
|
||||
return 0 unless defined($pgid) && $pgid =~ /\A[1-9][0-9]*\z/;
|
||||
return 0 unless !kill(0, -$pgid) && $!{ESRCH};
|
||||
delete($self->{workers}{$pgid});
|
||||
my $dir = _worker_dir($self->{path});
|
||||
opendir(my $dh, $dir) or return 0;
|
||||
@@ -884,6 +888,12 @@ sub sweep_stranded {
|
||||
my $lock_of = sub { my $p = shift; $p =~ s/\.borrow(?:\.[0-9]+)?\z//; return $p };
|
||||
for my $d (sort { ($b =~ /\.borrow(?:\.[0-9]+)?\z/ ? 1 : 0) <=> ($a =~ /\.borrow(?:\.[0-9]+)?\z/ ? 1 : 0)
|
||||
|| $a cmp $b } @found) {
|
||||
my @busy = live_workers($lock_of->($d));
|
||||
if (@busy) {
|
||||
push @report, { path => $d, action => 'kept',
|
||||
why => "build workers of process group $busy[0]{pgid} still exist" };
|
||||
next;
|
||||
}
|
||||
if ($d =~ /\.borrow(?:\.[0-9]+)?\z/) {
|
||||
unless ($opt{exclusive}) {
|
||||
push @report, { path => $d, action => 'kept',
|
||||
|
||||
Reference in New Issue
Block a user