bionic 1.6.3: 1. Verified that the lock is hold during dpkg run added lslocks to aptitude prerm:
$ lxc exec bbb -- strace -o $PWD/log -e openat,open,close,fcntl python3 $PWD/foo.py (Reading database ... 28970 files and directories currently installed.) Removing aptitude (0.8.10-6ubuntu1) ... COMMAND PID TYPE SIZE MODE M START END PATH atd 198 POSIX 4B WRITE 0 0 0 /run/atd.pid python3 2751 POSIX 0B WRITE 0 0 0 /var/lib/dpkg/lock-frontend python3 2751 POSIX 0B WRITE 0 0 0 /var/cache/apt/archives/lock cron 196 FLOCK 4B WRITE 0 0 0 /run/crond.pid dpkg 2761 POSIX 0B WRITE 0 0 0 /var/lib/dpkg/lock Removing aptitude-common (0.8.10-6ubuntu1) ... Processing triggers for man-db (2.8.3-2) ... 2. With system lock helt in my script: #!/usr/bin/python3 import apt, apt_pkg c = apt.Cache() if c["aptitude-common"].is_installed: c["aptitude-common"].mark_delete() else: c["aptitude-common"].mark_install() with apt_pkg.SystemLock(): c.commit() $ lxc exec bbb -- strace -o $PWD/log.locked -e openat,open,close,fcntl python3 $PWD/foo.py (Reading database ... 28970 files and directories currently installed.) Removing aptitude (0.8.10-6ubuntu1) ... COMMAND PID TYPE SIZE MODE M START END PATH atd 198 POSIX 4B WRITE 0 0 0 /run/atd.pid dpkg 3106 POSIX 0B WRITE 0 0 0 /var/lib/dpkg/lock cron 196 FLOCK 4B WRITE 0 0 0 /run/crond.pid python3 3096 POSIX 0B WRITE 0 0 0 /var/lib/dpkg/lock-frontend python3 3096 POSIX 0B WRITE 0 0 0 /var/cache/apt/archives/lock Removing aptitude-common (0.8.10-6ubuntu1) ... Processing triggers for man-db (2.8.3-2) ... Works fine. 3. Investigating strace also shows that the lock-frontend is acquired once, and not released until the end. ** Tags removed: verification-needed-bionic ** Tags added: verification-done-bionic -- You received this bug notification because you are a member of Ubuntu Touch seeded packages, which is subscribed to python-apt in Ubuntu. https://bugs.launchpad.net/bugs/1795407 Title: python-apt frontend locking Status in python-apt package in Ubuntu: Fix Released Status in python-apt source package in Xenial: Fix Committed Status in python-apt source package in Bionic: Fix Committed Bug description: [Impact] Add support to python-apt for frontend locking. This is a bit more complicated, and also requires some other restructuring: (1) The archives lock was only taken for a short time, when it should have been kept for the duration of an installation, as otherwise debs could disappear from archives/ while the install is running. (2) There was no lock handling at all. Tools essentially acquire the lock, and then release it before commit(). The fix is based on the apt fix, which makes apt_pkg.SystemLock() manage both the frontend and the normal lock, and allows code to call apt_pkg.pkgsystem_unlock_inner() and apt_pkg.pkgsystem_lock_inner() around dpkg invocations to release the inner lock. Cache.commit() takes care of locking itself now. It releases the inner lock as needed for dpkg invocations. It also now requires apt_pkg.SystemLock to be hold - if it is not, it will acquire it itself. [Test case] 1. Mark a package in the cache for install/removal and commit() - FE lock should be taken while dpkg is running. 2. Mark a package in the cache for install/removal and commit() while holding the lock. Releasing the lock afterwards should still work correctly, and the FE lock should never be released 3. Observe that the archive lock is not released until the last dpkg run The locking behavior can be observed via strace. [Regression potential] The dpkg lock changed the most: Some lock counting might go wrong and programs might fail as a result. Any problems will be isolated, though - dpkg still acquires its locks, and if a lock miscount happens, apt would not tell dpkg to skip acquiring the frontend lock, so even if we were losing the lock anywhere, dpkg would still try to acquire it and not run unlocked. The archive lock done by commit()/fetch_archives() in apt.Cache() is now hold as long as the fetcher object exists though (as it uses the fetcher's get_lock method), which might cause unexpected behavior in apps not expecting that. The lists/ lock is unaffected by the changes, so there should not be any regressions when it comes to updating index files. [Other info (1)] CI changes: There were some improvements to type hints for mypy needed to make type checks pass, and changes to the CI's Dockerfile to pull a new apt from the apt stable PPA (as a new enough apt is only in unapproved atm). Neither of those files are used anywhere outside of the package, so they should not cause any problems. [Other info (2)] This is part of a wider series of SRUs for frontend locking - dpkg (bug 1796081) - apt (bug 1781169) - python-apt (bug 1795407) - packagekit (bug 1795614) - unattended-upgrades (bug 1789637) - aptdaemon (no bug filed yet) Further details about frontend locking can be found in https://lists.debian.org/debian-dpkg/2017/01/msg00044.html - This SRU depends on the apt SRU above, and breaks unattended- upgrades in bionic without its SRU due to a bug in the u-u code in handling the new API. To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/python-apt/+bug/1795407/+subscriptions -- Mailing list: https://launchpad.net/~touch-packages Post to : touch-packages@lists.launchpad.net Unsubscribe : https://launchpad.net/~touch-packages More help : https://help.launchpad.net/ListHelp