Reduce time to detect hanging builds by using standard output-based detection.

Resolves: RHEL-191649
This commit is contained in:
Tom Deseyn 2026-07-02 20:28:24 +02:00
parent 8b64e99a86
commit 1018dfa1c0

View File

@ -57,7 +57,7 @@
Name: dotnet%{dotnetver}
Version: %{sdk_rpm_version}
Release: 2%{?dist}
Release: 3%{?dist}
Summary: .NET Runtime and SDK
License: 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
@ -556,6 +556,8 @@ function retry_until_success {
set +e
while [[ $exit_code != 0 ]] && [[ $tries != 0 ]]; do
(( tries = tries - 1 ))
# Clean stale build state so retries start fresh.
rm -rf .packages $(find . -name artifacts -type d)
"$@"
exit_code=$?
done
@ -563,6 +565,66 @@ function retry_until_success {
return $exit_code
}
# Runs a command and kills it if it produces no output.
# Use a longer timeout on machines with fewer cores since builds are slower.
function output_timeout {
# 30m on machines with more than 4 cores, 60m on smaller machines where builds are slower.
# The aarch64 Neoverse N1 CI machines have 4 cores and need the longer timeout.
local nprocs=$(nproc)
local idle_timeout=1800
if (( nprocs <= 4 )); then
idle_timeout=3600
fi
# Create a pipe we'll read the output from for timeout detection.
local fifo=$(mktemp -u)
mkfifo "$fifo"
# Create a process group so we can kill every process including children.
# And use a long timeout (5h) in (the unlikely) case output timeout detection continues to be triggered.
setsid timeout --foreground 5h "$@" &> "$fifo" &
local cmd_pid=$!
# Read lines from the output with a timeout.
# Disable tracing to avoid 'set -x' noise from the read loop appearing in the output.
local timed_out=false
local traceflags=$-
set +x
while true; do
local rc=0
IFS= read -t $idle_timeout -r line || rc=$?
if (( rc == 0 )); then
printf '%s\n' "$line"
elif (( rc > 128 )); then
echo "output_timeout: no output for ${idle_timeout}s" >&2
timed_out=true
break
else
[[ -z $line ]] || printf '%s\n' "$line"
break
fi
done < "$fifo"
[[ $traceflags != *x* ]] || set -x
if $timed_out; then
# Hang detected: kill the process group, then collect the exit code.
kill -9 -- -$cmd_pid 2>/dev/null || true
wait $cmd_pid 2>/dev/null
local exit_code=$?
else
# Normal exit: collect the real exit code, then clean up any orphaned processes.
wait $cmd_pid 2>/dev/null
local exit_code=$?
kill -9 -- -$cmd_pid 2>/dev/null || true
fi
# Cleanup.
rm -f "$fifo"
return $exit_code
}
cat >dotnet-rpm-build.sh <<EOF
#!/bin/bash
@ -590,7 +652,7 @@ EOF
chmod +x dotnet-rpm-build.sh
VERBOSE=1 retry_until_success $max_attempts \
timeout 5h \
output_timeout \
./dotnet-rpm-build.sh
@ -779,6 +841,10 @@ export COMPlus_LTTng=0
%changelog
* Thu Jul 02 2026 Tom Deseyn <tdeseyn@redhat.com> - 8.0.128-3
- Reduce time to detect hanging builds
- Resolves: RHEL-191649
* Wed Jun 10 2026 Tom Deseyn <tdeseyn@redhat.com> - 8.0.128-2
- Update to .NET SDK 8.0.128 and Runtime 8.0.28
- Resolves: RHEL-181053