From 727e96e527ad44d052d90b85b792f8453f2ed154 Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Tue, 20 Oct 2026 09:57:54 +0300 Subject: [PATCH] Snap on Launchpad: an outage there gets more attempts and longer pauses, not three strikes. v12.56's ppc64el snap failed after 20 minutes of its five-hour budget. Attempt 1's Launchpad builder lost its TLS connection while cloning our source ("RPC failed; curl 56 GnuTLS recv error ... fatal: early EOF"). Attempts 2 and 3 followed a minute apart each, and both met Launchpad's own "HTTP Error 503: Service Unavailable" / "Error: Timeout". s390x, riscv64 and armhf each lost an attempt the same night and recovered. infra_failure() recognises an attempt that failed on Launchpad rather than on WeKan: an HTTP 5xx or timeout from its API, or, in that attempt's own build log, a dropped git/TLS transfer or the build farm's package proxy failing. Such an attempt earns another one, up to six, after a pause of 5, 10, 15... minutes, never running past the shared deadline. Every other failure keeps three attempts and the 60s pause; a missing stage-package is not retried longer. tests/snapLaunchpadInfraRetry.test.cjs runs the workflow's own infra_failure() against logs shaped like v12.56's, and against the negatives: a missing stage-package, an earlier attempt's log, a 4xx. Thanks to xet7 ! --- .github/workflows/release-all.yml | 34 ++++++++++- tests/snapLaunchpadInfraRetry.test.cjs | 83 ++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 tests/snapLaunchpadInfraRetry.test.cjs diff --git a/.github/workflows/release-all.yml b/.github/workflows/release-all.yml index 65554ab4d9..212153ad1e 100644 --- a/.github/workflows/release-all.yml +++ b/.github/workflows/release-all.yml @@ -5176,6 +5176,24 @@ jobs: } attempts=3 + # Launchpad being down is not three strikes. v12.56 ppc64el: attempt + # 1's builder lost its TLS connection cloning our source ("RPC failed; + # curl 56 GnuTLS recv error ... early EOF"), and attempts 2 and 3, a + # minute apart each, both met Launchpad's own "HTTP Error 503: Service + # Unavailable" / "Error: Timeout" - the job gave up after 20 minutes + # of a five-hour budget. An attempt that failed on Launchpad + # infrastructure earns another one, up to this many, after a pause + # that grows each time. + max_attempts=6 + infra_failure() { # did THIS attempt fail on Launchpad, not on WeKan? + grep -qsE 'HTTP Error 5[0-9][0-9]|Error: Timeout|Service Unavailable' "$remote_log" && return 0 + local log + for log in snapcraft-wekan-*.txt; do + [ -e "$log" ] && [ "$log" -nt "$attempt_marker" ] || continue + grep -qsE 'RPC failed; curl|GnuTLS recv error|fatal: early EOF|Gateway error \[IP: ' "$log" && return 0 + done + return 1 + } # Set once an attempt ends with Launchpad reporting the build as # finished without a snap ("Stopped:" / "Failed:" for this arch). # Recovery reconnects to that SAME build, so it can only download the @@ -5184,7 +5202,9 @@ jobs: # retried by submitting a fresh one. fresh_next=0 attempt_marker="$PWD/.tools/tmp/remote-build-attempt.start" - for i in $(seq 1 "$attempts"); do + i=0 + while [ "$i" -lt "$attempts" ]; do + i=$((i + 1)) # A partial file from a previous attempt must not be mistaken for # this attempt's artifact: snapcraft does not re-download a name it # already has, so the truncated one would be uploaded again. @@ -5283,6 +5303,14 @@ jobs: tail -n 120 "$sclog" echo "::endgroup::" done + pause=60 + if infra_failure; then + [ "$attempts" -lt "$max_attempts" ] && [ "$i" -ge "$attempts" ] && attempts=$((attempts + 1)) + # 5, 10, 15... minutes, never past the shared deadline. + pause=$((300 * i)) + [ "$pause" -le $((deadline - SECONDS - 600)) ] || pause=$(( deadline - SECONDS - 600 > 60 ? deadline - SECONDS - 600 : 60 )) + echo "::warning::Attempt $i failed on Launchpad infrastructure (an HTTP 5xx, a timeout or a dropped git/TLS transfer), not on WeKan; allowing up to $attempts attempts." + fi if [ "$i" -lt "$attempts" ]; then # Clear a half-pushed clone only when submission never reached # monitoring. A failed poll must keep the running build intact. @@ -5290,8 +5318,8 @@ jobs: echo "Clearing snapcraft's remote-build cache before retrying submission." rm -rf "$HOME/.cache/snapcraft/remote-build" fi - echo "Retrying in 60s..." - sleep 60 + echo "Retrying in ${pause}s..." + sleep "$pause" fi done echo "::error::Remote build ${MATRIX_ARCH} failed after $attempts attempts (no wekan_${VERSION}_${MATRIX_ARCH}.snap produced). The Launchpad build log printed above says why; the builds are also at https://launchpad.net/~xet7/+snaps" >&2 diff --git a/tests/snapLaunchpadInfraRetry.test.cjs b/tests/snapLaunchpadInfraRetry.test.cjs new file mode 100644 index 0000000000..1ea3f03403 --- /dev/null +++ b/tests/snapLaunchpadInfraRetry.test.cjs @@ -0,0 +1,83 @@ +'use strict'; + +// v12.56 ppc64el snap: attempt 1's Launchpad builder lost its TLS connection +// cloning our source, and attempts 2 and 3, a minute apart, both met +// Launchpad's "HTTP Error 503: Service Unavailable" - the job gave up after 20 +// minutes of a five-hour budget. An attempt that failed on Launchpad +// infrastructure now earns another (up to max_attempts) after a growing pause. +// This runs the workflow's own infra_failure() against logs shaped like that +// run's, and against the failures that must stay at three attempts. +// Run: node tests/snapLaunchpadInfraRetry.test.cjs + +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const { spawnSync } = require('node:child_process'); + +const ROOT = path.join(__dirname, '..'); +const wf = fs.readFileSync(path.join(ROOT, '.github/workflows/release-all.yml'), 'utf8'); +const step = wf.slice(wf.indexOf('- name: Build the ${{ matrix.arch }} snap on Launchpad')); +let passed = 0; +function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); } + +// The function exactly as the workflow has it, de-indented from the YAML block. +const fnText = /\n( +)infra_failure\(\) \{[\s\S]*?\n\1\}\n/.exec(step)[0] + .split('\n').map(l => l.replace(/^ {10}/, '')).join('\n'); + +function infraFailure({ remoteLog = '', buildLogs = {}, oldBuildLogs = {} }) { + const dir = fs.mkdtempSync(path.join(process.env.TMPDIR || os.tmpdir(), 'lp-')); + try { + for (const [name, text] of Object.entries(oldBuildLogs)) { + fs.writeFileSync(path.join(dir, name), text); + fs.utimesSync(path.join(dir, name), new Date(2000, 0, 1), new Date(2000, 0, 1)); + } + fs.writeFileSync(path.join(dir, 'marker'), ''); + fs.utimesSync(path.join(dir, 'marker'), new Date(2010, 0, 1), new Date(2010, 0, 1)); + for (const [name, text] of Object.entries(buildLogs)) fs.writeFileSync(path.join(dir, name), text); + fs.writeFileSync(path.join(dir, 'remote.log'), remoteLog); + const script = `cd "${dir}"; remote_log=remote.log; attempt_marker=marker\n${fnText}\ninfra_failure`; + return spawnSync('bash', ['-c', script]).status === 0; + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + } +} + +test('v12.56 attempt 1: the builder lost TLS cloning our source', () => { + assert.equal(infraFailure({ buildLogs: { 'snapcraft-wekan-x_ppc64el.txt': + "Cloning into 'snapcraft-wekan-f66b'...\nerror: RPC failed; curl 56 GnuTLS recv error (-110): The TLS connection was non-properly terminated.\nfatal: early EOF\nBuild failed\n" } }), true); +}); + +test('v12.56 attempts 2 and 3: Launchpad answered 503 / Timeout', () => { + assert.equal(infraFailure({ remoteLog: 'lazr.restfulclient.errors.ServerError: HTTP Error 503: Service Unavailable\nError: Timeout' }), true); +}); + +test('the build farm\'s package proxy failing is infrastructure too', () => { + assert.equal(infraFailure({ buildLogs: { 'snapcraft-wekan-x_s390x.txt': 'Failed to fetch package: 501 Gateway error [IP: 10.10.10.1 8222]' } }), true); +}); + +test('negative: a missing stage-package is WeKan\'s, and keeps three attempts', () => { + assert.equal(infraFailure({ buildLogs: { 'snapcraft-wekan-x_armhf.txt': "Stage package not found in part 'wekan': libssl3\nBuild failed" } }), false); +}); + +test('negative: an earlier attempt\'s log does not count for this one', () => { + assert.equal(infraFailure({ oldBuildLogs: { 'snapcraft-wekan-old_ppc64el.txt': 'error: RPC failed; curl 56' } }), false); +}); + +test('negative: a 4xx from Launchpad is not taken for an outage', () => { + assert.equal(infraFailure({ remoteLog: 'HTTP Error 400: Bad Request' }), false); +}); + +test('the loop grows only on infrastructure failures, within a cap and the deadline', () => { + assert.match(step, /attempts=3\n/); + assert.match(step, /max_attempts=6\n/); + assert.match(step, /i=0\n\s+while \[ "\$i" -lt "\$attempts" \]; do\n\s+i=\$\(\(i \+ 1\)\)/, 'a loop whose bound can grow'); + assert.doesNotMatch(step, /for i in \$\(seq 1 "\$attempts"\)/, 'negative: not a bound fixed at the start'); + const grow = step.slice(step.indexOf('if infra_failure; then'), step.indexOf('if [ "$i" -lt "$attempts" ]; then')); + assert.match(grow, /\[ "\$attempts" -lt "\$max_attempts" \] && \[ "\$i" -ge "\$attempts" \] && attempts=\$\(\(attempts \+ 1\)\)/); + assert.match(grow, /pause=\$\(\(300 \* i\)\)/, 'a pause that grows'); + assert.match(grow, /deadline - SECONDS - 600/, 'and never runs past the five-hour budget'); + assert.match(step, /sleep "\$pause"/); +}); + +console.log(`snapLaunchpadInfraRetry: ${passed} tests passed`);