diff options
| author | tv <tv@krebsco.de> | 2026-11-20 01:26:11 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-20 01:26:11 +0000 |
| commit | f02b09eae7e806f2fe9caa26b4975b94351d7e27 (patch) | |
| tree | c043f6443dac2cfb73446bba993cb9ac3b58c300 /pkgs/populate/tests/scenarios.nix | |
| parent | 61840ec59bc13b9b2ae6d29fff7276c849684941 (diff) | |
populate: fail when losing the lock, keepalives for the ssh connection
The command holding the lock can end while populate runs: killed on the
target, e.g. by the OOM killer, or with the shared ssh connection, e.g.
when its master gets killed, after which populate's next command would
start a new one, and go on without the lock. When that command ends, so
does what populate runs it with, ssh or sh, which populate's child is.
So Context::shell, which every command on the target goes through,
before what it changes, and before the record, checks that the child is
still running, failing otherwise. A run that wasn't locked throughout
doesn't get recorded, and its journal stays, so the next record tells
what it changed. Context keeps the lock, which clean_up releases.
The keepalives end the shared connection, and with it the command
holding the lock on the target, about a minute after the target stops
answering, e.g. when the network fails, instead of when TCP gives up,
which may take hours.
lock-lost kills the command holding the lock from a pipe source.
Diffstat (limited to 'pkgs/populate/tests/scenarios.nix')
| -rw-r--r-- | pkgs/populate/tests/scenarios.nix | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/pkgs/populate/tests/scenarios.nix b/pkgs/populate/tests/scenarios.nix index bd3bf83..a5ac6ea 100644 --- a/pkgs/populate/tests/scenarios.nix +++ b/pkgs/populate/tests/scenarios.nix @@ -884,6 +884,41 @@ in } ]; }) + # The command holding the lock ending, here when a pipe source kills + # it, or what runs it on the deploying machine, fails the run before the + # next command on the target, without a record. On a remote target, + # that's the ssh client running it, and on the local one the command + # itself, cat by then, holding the lock file open. + (s "lock-lost" { + prepareDeployer = '' + cat > /tmp/lose-lock <<'EOF' + #!/bin/sh + pkill -f 'exec cat >/dev/null' || : + for fd in /proc/[0-9]*/fd/*; do + case $(readlink "$fd" 2>/dev/null) in + */.populate/lock) + pid=''${fd#/proc/} + kill "''${pid%%/*}" || : + ;; + esac + done + sleep 1 + echo x + EOF + chmod +x /tmp/lose-lock + ''; + phases = [{ + sources = { + a.pipe = "/tmp/lose-lock"; + b.symlink = "a"; + }; + expect.fail = "error: populate lost the lock on"; + check = '' + test ! -e "$T"/.populate/run.json || fail "record written" + test -e "$T"/.populate/journal || fail "journal missing" + ''; + }]; + }) # A materialized input is a writable copy, patched and with a rewritten # lock file, which gets made again only when what it derives from # changes, and becomes a link again when not materialized anymore. |
