** Patch added: "stonking debdiff" https://bugs.launchpad.net/ubuntu/+source/reprepro/+bug/2169601/+attachment/6022563/+files/reprepro_5.4.6+really5.3.2-2ubuntu0.26.10.1.debdiff
** Description changed: [ Impact ] reprepro keeps all repository state in Berkeley DB files under db/ (checksums.db, packages.db, references.db, packagenames.db). It doesn't use a transactional environment, so these files are only consistent if reprepro closes them properly before it exits. reprepro catches SIGTERM, SIGINT, SIGQUIT and SIGABRT. On those it stops cleanly, closes the databases and removes db/lockfile. It does not catch SIGHUP. If the terminal it's running on goes away (an ssh session drops, the process that started it on a pty exits, the machine reboots), reprepro is killed immediately with its databases still open. If that happens while reprepro is writing, that is between "Installing (and possibly deleting) packages..." and closing the databases, the databases are corrupted and db/lockfile is left behind. Landscape Server runs into this in normal operation. It mirrors Ubuntu archives with reprepro, and its job-handler service runs "reprepro update" on a pty (Twisted spawnProcess with usePTY=True) so it can read the line-buffered --show-percent progress output. Stopping job-handler, for example when restarting Landscape or rebooting, closes that pty and reprepro gets SIGHUP. If a mirror sync is installing packages at that moment, the distribution's databases are corrupted. All series and pockets of a distribution share one db/, so the damage isn't limited to the pocket that was syncing. Landscape only gets sync progress from reprepro's "Got N%" lines, so a later sync that loops on the damaged btree sits at 0% forever without reporting an error. [ Test Plan ] The test imports a large number of small packages into a local repository and sends reprepro a SIGHUP partway through. You need two terminals. Commands are shown without indentation so they can be pasted as they are. 1. Install reprepro and note the installed version: sudo apt update sudo apt install reprepro apt policy reprepro 2. Build 10,000 small test packages. This takes a couple of minutes. Importing them takes around 20 seconds, which leaves plenty of time to interrupt the import by hand. mkdir -p ~/sru-test/build/DEBIAN ~/sru-test/pkgs cd ~/sru-test for i in $(seq -w 1 10000); do cat > build/DEBIAN/control <<EOF Package: sru-test-$i Version: 1.0 Architecture: all Section: misc Priority: optional Maintainer: Test <[email protected]> Description: test package for LP 2169601 EOF dpkg-deb --build build pkgs/$i.deb >/dev/null done 3. Create an empty repository in ~/sru-test/repo1: mkdir -p ~/sru-test/repo1/conf Create ~/sru-test/repo1/conf/distributions with these three lines, with no leading spaces (use the architecture that "dpkg --print-architecture" prints): Codename: test Components: main Architectures: amd64 4. In the first terminal, start importing the packages: reprepro -b ~/sru-test/repo1 includedeb test ~/sru-test/pkgs/*.deb Wait about five seconds, then send reprepro a hangup from the second terminal: pkill -HUP -x reprepro When reprepro exits, check its exit status in the first terminal: echo $? Then try to use the repository: reprepro -b ~/sru-test/repo1 check Expected with the current package: - reprepro stops at once, and bash prints "Hangup". You may also see a "Broken pipe" error from zstd. - The exit status is 129. - ~/sru-test/repo1/db/lockfile is still there, and "reprepro check" refuses to run with "The lock file '.../db/lockfile' already exists...". Whether the databases are actually corrupted depends on timing, so the test doesn't depend on it. The abrupt exit and the leftover lock file are enough to show the bug. Leave repo1 as it is. 5. Install reprepro with the fix from the -proposed pocket. Then repeat steps 3 - and 4 with a new repository, ~/sru-test/repo2. + and 4 with a new repository, ~/sru-test/repo2. Expected with the fixed package: - reprepro prints "Interruption in progress, interrupt again to force-stop it" and exits within a second or two. - The exit status is 247, not 129. - ~/sru-test/repo2/db/lockfile has been removed, and "reprepro check" runs without errors. - A warning that the database "was modified but no index file was exported" is expected. Interrupting the import stops it, but it doesn't undo the packages already added. If reprepro is still running a minute after the hangup, the test has failed. Keep the output, and don't send a second signal. 6. Check that repo2 still works and that the interrupted import can be finished: cd ~/sru-test/repo2 reprepro -b . check reprepro -b . includedeb test ~/sru-test/pkgs/*.deb reprepro -b . export test reprepro -b . check reprepro -b . list test | wc -l Expected: the includedeb prints "Skipping inclusion of ..." for each package imported before the hangup, then adds the rest. Each command finishes within a minute, and the last one prints 10000. A command that hangs means the database is damaged, and the test has failed. [ Where problems could occur ] The patch only changes how signals are set up at the start of main(). It doesn't touch repository contents, the database format or any command line options. If the change is wrong, it would show up in how reprepro behaves when its terminal hangs up. It could ignore a SIGHUP it should act on, or it could still be killed immediately without cleaning up. + This changes the exit status from 129 to 247, so any wrapper scripts + expecting exit code 129 could break. + [ Other Info ] Upstream commit: https://salsa.debian.org/debian/reprepro/-/commit/e4dfe4f2857a3566fa944527156594024009595a The fix is merged into Debian's master branch: https://salsa.debian.org/debian/reprepro/-/merge_requests/22 ** Changed in: reprepro (Ubuntu Jammy) Importance: Undecided => Medium ** Changed in: reprepro (Ubuntu Noble) Importance: Undecided => Medium ** Changed in: reprepro (Ubuntu Resolute) Status: New => Confirmed ** Changed in: reprepro (Ubuntu Jammy) Status: New => Confirmed ** Changed in: reprepro (Ubuntu Noble) Status: New => Confirmed ** Changed in: reprepro (Ubuntu Stonking) Status: New => Confirmed ** Changed in: reprepro (Ubuntu Resolute) Importance: Undecided => Medium ** Changed in: reprepro (Ubuntu Stonking) Importance: Undecided => Medium -- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/2169601 Title: SIGHUP during db write corrupts the repository To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/reprepro/+bug/2169601/+subscriptions -- ubuntu-bugs mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs
