Potential inconsistency due to system halt/reboot being allowed when package installation in progress

Bug #1820886 reported by João Pedro Seara on 2019-03-19
20
This bug affects 1 person
Affects Status Importance Assigned to Milestone
apt (Ubuntu)
Medium
Julian Andres Klode
Xenial
Undecided
Unassigned
Bionic
Undecided
Unassigned
Cosmic
Undecided
Unassigned
Disco
Undecided
Unassigned

Bug Description

[System]
Any current Ubuntu Desktop/Server supported release (Trusty, Xenial, Bionic, Cosmic).

[Impact]
Package installation turns into an inconsistent state if system is rebooted in the middle of an apt install/upgrade.

[Test Case]
1. User1 at Ubuntu box issues "sudo apt-get upgrade";
2. User2 at Ubuntu box issues "shutdown -r" or reboots it using the GUI;
3. System reboots and potentially turns into an inconsistent state.

[Remarks]
APT should automatically inhibit system halts/reboots while packages being installed/removed. A similar behavior to what is shown by unattended-upgrades.

summary: - Inhibit system halt when package installation in progress
+ System halt/reboot is allowed when package installation in progress
summary: - System halt/reboot is allowed when package installation in progress
+ Potential inconsistency due to system halt/reboot being allowed when
+ package installation in progress
tags: added: sts
no longer affects: landscape-client
description: updated
description: updated
tags: added: id-5c912dccec34916fc8563ef9
Changed in apt (Ubuntu):
status: New → Triaged
assignee: nobody → Julian Andres Klode (juliank)
importance: Undecided → High
importance: High → Medium
Julian Andres Klode (juliank) wrote :

This has been on my agenda for quite some time. It means apt will need to talk dbus, and it might need to be able to react to a shutdown notification from dbus, which might get pretty complex, but I have not checked in detail.

It's not clear yet which dbus library to use. Starting with systemd's library would be fine, but we might eventually want to move to gdbus if we choose to implement a new apt daemon in apt using dbus, to not have it be linux-specific.

Julian Andres Klode (juliank) wrote :

Suggested workaround:

* Create a script that tries to lock the apt locks, until it succeeds, then exits
* Make that run in ExecStart in a service WantedBy=shutdown.target

Probably some issues regarding to services and stuff, but better than nothing.

Julian Andres Klode (juliank) wrote :

Something like that Python script should be enough really to catch most issues:

import apt_pkg, os

apt_pkg.init()

dir = apt_pkg.config.find_dir("Dir::Cache::Archives")
while True:
  try:
    apt_pkg.get_lock(os.path.join(dir, "lock"))
    break
  except:
    continue

Balint Reczey (rbalint) wrote :

@juliank The proposed service would reopen LP: #1778219 , just for apt. :-(

IMO command line apt should inhibit shutdown and systemd should respect that even when running reboot as root.

Julian Andres Klode (juliank) wrote :
Changed in apt (Ubuntu):
status: Triaged → In Progress
Julian Andres Klode (juliank) wrote :

OK so where we are right now:

- Needs coordination with unattended-upgrades to avoid breaking its features
- Inhibitors are ignored for root: https://github.com/systemd/systemd/pull/9356

Hello João, or anyone else affected,

Accepted apt into disco-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/apt/1.8.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-disco to verification-done-disco. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-disco. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in apt (Ubuntu Disco):
status: New → Fix Committed
tags: added: verification-needed verification-needed-disco
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apt - 1.8.1+19.10

---------------
apt (1.8.1+19.10) eoan; urgency=medium

  * Upload to eoan

apt (1.8.1) unstable; urgency=medium

  * Add test case for local-only packages pinned to never
  * Prevent shutdown while running dpkg (LP: #1820886)
  * Add linux-{buildinfo,image-unsigned,source} versioned kernel pkgs
    (LP: #1821640)

 -- Julian Andres Klode <email address hidden> Mon, 06 May 2019 11:26:17 +0200

Changed in apt (Ubuntu):
status: In Progress → Fix Released
Julian Andres Klode (juliank) wrote :

Installed 1.8.1, running reboot as a user is inhibited:

$ reboot
Operation inhibited by "APT" (PID 3208 "apt", user root), reason is "APT is installing or removing packages".
Please retry operation after closing inhibitors and logging out other users.
Alternatively, ignore inhibitors and users with 'systemctl reboot -i'.

As root it obviously is not, as inhibitors are ignored, nothing we can do about that now.

tags: added: verification-done-disco
removed: verification-needed-disco
Changed in apt (Ubuntu Cosmic):
status: New → In Progress
Changed in apt (Ubuntu Bionic):
status: New → In Progress
Changed in apt (Ubuntu Xenial):
status: New → In Progress
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apt - 1.8.1

---------------
apt (1.8.1) unstable; urgency=medium

  * Add test case for local-only packages pinned to never
  * Prevent shutdown while running dpkg (LP: #1820886)
  * Add linux-{buildinfo,image-unsigned,source} versioned kernel pkgs
    (LP: #1821640)

 -- Julian Andres Klode <email address hidden> Mon, 06 May 2019 10:41:52 +0200

Changed in apt (Ubuntu Disco):
status: Fix Committed → Fix Released

The verification of the Stable Release Update for apt has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

Hello João, or anyone else affected,

Accepted apt into cosmic-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/apt/1.7.5 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-cosmic to verification-done-cosmic. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-cosmic. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in apt (Ubuntu Cosmic):
status: In Progress → Fix Committed
tags: added: verification-needed-cosmic
Changed in apt (Ubuntu Bionic):
status: In Progress → Fix Committed
tags: added: verification-needed-bionic
Brian Murray (brian-murray) wrote :

Hello João, or anyone else affected,

Accepted apt into bionic-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/apt/1.6.11 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-bionic to verification-done-bionic. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-bionic. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in apt (Ubuntu Xenial):
status: In Progress → Fix Committed
tags: added: verification-needed-xenial
Brian Murray (brian-murray) wrote :

Hello João, or anyone else affected,

Accepted apt into xenial-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/apt/1.2.32 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-xenial to verification-done-xenial. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-xenial. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

João Pedro Seara (jpseara) wrote :

I confirm the fix works for Bionic.

tags: added: verification-done-bionic
removed: verification-needed-bionic

Verified fix for Xenial:

ubuntu@xenial:~$ systemctl reboot
Operation inhibited by "APT" (PID 1311 "apt", user root), reason is "APT is installing or removing packages".
Please retry operation after closing inhibitors and logging out other users.
Alternatively, ignore inhibitors and users with 'systemctl reboot -i'.

ubuntu@xenial:~$ dpkg -l | grep apt
ii apt 1.2.32 amd64 commandline package manager

tags: added: verification-done-xenial
removed: verification-needed-xenial
Julian Andres Klode (juliank) wrote :

Verified for 1.7.5 in cosmic:

ubuntu@apt-cosmic:~$ systemctl reboot
Operation inhibited by "APT" (PID 683 "apt", user root), reason is "APT is installing or removing packages".
Please retry operation after closing inhibitors and logging out other users.
Alternatively, ignore inhibitors and users with 'systemctl reboot -i'.

tags: added: verification-done verification-done-cosmic
removed: verification-needed verification-needed-cosmic
Julian Andres Klode (juliank) wrote :

Verified again on bionic - 1.6.11, as the previous verification missed the version number.

$ systemctl reboot
Operation inhibited by "APT" (PID 2015 "apt", user root), reason is "APT is installing or removing packages".
Please retry operation after closing inhibitors and logging out other users.
Alternatively, ignore inhibitors and users with 'systemctl reboot -i'.

Julian Andres Klode (juliank) wrote :

For 1.7.5/cosmic:

Regression in autopkgtest for autopkgtest (i386): test log

This also happens with other runs, seems to be spurious.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apt - 1.7.5

---------------
apt (1.7.5) cosmic; urgency=medium

  * Add test case for local-only packages pinned to never
  * Prevent shutdown while running dpkg (LP: #1820886)
  * Add linux-{buildinfo,image-unsigned,source} versioned kernel pkgs
    (LP: #1821640)

 -- Julian Andres Klode <email address hidden> Tue, 07 May 2019 11:04:15 +0200

Changed in apt (Ubuntu Cosmic):
status: Fix Committed → Fix Released
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apt - 1.6.11

---------------
apt (1.6.11) bionic; urgency=medium

  * Add test case for local-only packages pinned to never
  * Prevent shutdown while running dpkg (LP: #1820886)
  * Add linux-{buildinfo,image-unsigned,source} versioned kernel pkgs
    (LP: #1821640)

 -- Julian Andres Klode <email address hidden> Tue, 07 May 2019 11:19:29 +0200

Changed in apt (Ubuntu Bionic):
status: Fix Committed → Fix Released
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apt - 1.2.32

---------------
apt (1.2.32) xenial; urgency=medium

  * Add test case for local-only packages pinned to never
  * Prevent shutdown while running dpkg (LP: #1820886)
  * Add linux-{buildinfo,image-unsigned,source} versioned kernel pkgs
    (LP: #1821640)

 -- Julian Andres Klode <email address hidden> Tue, 07 May 2019 12:57:03 +0200

Changed in apt (Ubuntu Xenial):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers