Skip to content

[AI Generated] Wait for apt/dpkg frontend lock holders in Debian package wait#4556

Merged
LiliDeng merged 2 commits into
microsoft:mainfrom
johnsongeorge-w:bugfix/apt_frontend_lock_wait_240626_154311
Jun 30, 2026
Merged

[AI Generated] Wait for apt/dpkg frontend lock holders in Debian package wait#4556
LiliDeng merged 2 commits into
microsoft:mainfrom
johnsongeorge-w:bugfix/apt_frontend_lock_wait_240626_154311

Conversation

@johnsongeorge-w

Copy link
Copy Markdown
Collaborator

Problem

wait_running_package_process() only checked pidof dpkg dpkg-deb, which misses frontend-lock holders such as unattended-upgrades and apt-get that hold the apt/dpkg frontend lock without a running dpkg process. As a result, package installs could start before a boot-time unattended-upgrade run finished, failing with:

  • E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process ... (unattended-upgr)
  • transient E: Unable to correct problems, you have held broken packages

This was observed on Ubuntu Pro FIPS images, where unattended-upgrades upgrades the kernel at first boot.

Fix

Add _is_package_lock_held(), which uses fuser on the apt/dpkg lock files (/var/lib/dpkg/lock-frontend, /var/lib/dpkg/lock, /var/lib/apt/lists/lock, /var/cache/apt/archives/lock). wait_running_package_process() now waits until both no dpkg process is running and no process holds any apt/dpkg lock before proceeding. If fuser is unavailable, detection degrades safely to the prior pidof behavior. Nothing is disabled, stopped, or killed — the wait simply accounts for lock holders it previously missed.

Validation

  • Lint: flake8, pylint (10/10), darker, mypy — clean for the changed file
  • Smoke test PASSED (Provisioning.smoke_test, Ubuntu Pro FIPS 22.04, fresh boot): 1 passed / 0 failed / 0 skipped; no lock or install errors

…age wait

wait_running_package_process() only checked 'pidof dpkg dpkg-deb', which
misses holders such as unattended-upgrades and apt-get that hold the
apt/dpkg frontend lock without a running dpkg process. This caused
package installs to start before a boot-time unattended-upgrade run
finished, failing with 'Could not get lock /var/lib/dpkg/lock-frontend'
or transient 'held broken packages' errors.

Add _is_package_lock_held() (via fuser on the apt/dpkg lock files) and
require both no dpkg process and no lock holder before proceeding. If
fuser is unavailable, detection degrades safely to the prior pidof
behavior.
Copilot AI review requested due to automatic review settings June 25, 2026 03:20
@johnsongeorge-w johnsongeorge-w changed the title Wait for apt/dpkg frontend lock holders in Debian package wait [AI Generated] Wait for apt/dpkg frontend lock holders in Debian package wait Jun 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves Debian/Ubuntu package-operation stability by extending wait_running_package_process() to also wait on apt/dpkg lock holders (not just dpkg/dpkg-deb processes), reducing boot-time install flakiness caused by unattended upgrades.

Changes:

  • Add _is_package_lock_held() to detect active holders of apt/dpkg lock files via fuser.
  • Update wait_running_package_process() to wait until both: no dpkg process is running and no apt/dpkg lock is held.

Comment thread lisa/operating_system.py
Comment thread lisa/operating_system.py
…nstall

Background apt jobs (apt-daily*, unattended-upgrades) grab the dpkg frontend lock at boot, making the first package install race and fail with 'Could not get lock /var/lib/dpkg/lock-frontend ... (unattended-upgr)'. Mask these units with 'systemctl mask --now' at the start of Debian._initialize_package_installation so they cannot run now or after a reboot. Validated end-to-end on Ubuntu 22.04 (jammy) and Debian 12 (bookworm); Msr.verify_hyperv_platform_id PASSED on both with all 5 units masked to /dev/null.
@LiliDeng
LiliDeng merged commit 0747dc3 into microsoft:main Jun 30, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants