From 2edfa6bfe6656f107cd3359a59d6c90e39f4a2f9 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:24:28 -0300 Subject: [PATCH] test(xcat-core): nothing proves a dead worker cannot end the build with SIGPIPE start_build_worker releases a gated worker by writing one byte to a pipe. When the worker dies after the lock records its group and before that write, the pipe has no reader, and the write raises SIGPIPE. The default disposition ends the builder, which skips the cleanup that restores the Debian package tree and releases the build lock. The test kills the worker inside the record step and checks that the builder exits normally and reports the worker as not released. It fails on this tree: the builder ends on signal 13. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/build_worker_gate_sigpipe.t | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 xCAT-test/unit/build_worker_gate_sigpipe.t diff --git a/xCAT-test/unit/build_worker_gate_sigpipe.t b/xCAT-test/unit/build_worker_gate_sigpipe.t new file mode 100644 index 0000000000..2ab2fb1b87 --- /dev/null +++ b/xCAT-test/unit/build_worker_gate_sigpipe.t @@ -0,0 +1,64 @@ +#!/usr/bin/perl +# start_build_worker releases a gated worker by writing one byte to a pipe. When the worker +# dies after the record and before that write, the pipe has no reader. A write to it must +# fail with EPIPE and take the failure path. SIGPIPE must not end the build process, because +# a signal skips the cleanup that restores the checkout and releases the lock. +use strict; +use warnings; +use Test::More; +use POSIX (); +use FindBin qw($Bin); +use lib "$Bin/../../build-utils/lib"; +use XCAT::BuildUtils (); + +# A held lock whose attach the test controls. +{ + package FakeLock; + sub new { my ($class, $attach) = @_; return bless { attach => $attach }, $class } + sub attach { my ($self, $pgid) = @_; return $self->{attach}->($pgid) } + sub detach { return 1 } + sub release { return 0 } +} + +# Run start_build_worker in a stand-in for the builder, with the default SIGPIPE disposition. +# $attach runs as the record step. Returns the stand-in's wait status. +# Exit 2: the worker was refused. Exit 1: the worker was released. +sub launch_with { + my ($attach) = @_; + my $builder = fork(); + die "fork: $!" unless defined $builder; + unless ($builder) { + open(STDOUT, '>', '/dev/null'); + open(STDERR, '>', '/dev/null'); + $SIG{PIPE} = 'DEFAULT'; + local @XCAT::BuildUtils::LIVE_LOCKS = (FakeLock->new($attach)); + my ($pid, $ok) = XCAT::BuildUtils::start_build_worker(); + POSIX::_exit(3) unless defined $pid; + POSIX::_exit(0) unless $pid; # the released worker + waitpid($pid, 0); + POSIX::_exit($ok ? 1 : 2); + } + waitpid($builder, 0); + return $?; +} + +# ---- the worker dies after the record and before the release --------------------------- +{ + my $status = launch_with(sub { + my ($pgid) = @_; + kill('KILL', $pgid); + waitpid($pgid, 0); + return 1; + }); + is($status & 127, 0, 'the builder is not ended by a signal when the worker dies before release'); + is($status >> 8, 2, 'and start_build_worker reports the worker as not released'); +} + +# ---- control: a live worker is released ------------------------------------------------ +{ + my $status = launch_with(sub { 1 }); + is($status & 127, 0, 'control: the builder exits normally'); + is($status >> 8, 1, 'control: start_build_worker releases a live worker'); +} + +done_testing();