Repository navigation
fix: wait for background apt/dpkg before running unattended-upgrade - #388
Merged
Merged
Conversation
amits-2u
approved these changes
Oct 6, 2026
naincy128
added a commit
that referenced
this pull request
Oct 7, 2026
naincy128
added a commit
that referenced
this pull request
Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Deployments that include the common role, such as xqueue, sometimes fail at "Take security updates during ansible runs" on freshly launched Jammy (22.04) instances. This PR makes the security role wait for any background apt/dpkg activity to finish before it runs unattended-upgrade. It also spaces out the existing retries.
Failure
edx.ymlenables both of the following settings:SECURITY_UPGRADE_ON_ANSIBLE: trueunattended-upgradeduring the play.SECURITY_UNATTENDED_UPGRADES: trueapt-daily/apt-daily-upgradetimers also run upgrades in the background.When a new instance boots, the background timers can start upgrading packages immediately. The Ansible run may then compete with the background upgrade process for the
dpkglock and fail with anon-zero return code.The existing Ansible retries do not include a delay, so all retry attempts can be exhausted quickly, often before the background upgrade finishes.
Example from a
stage-xqueuerun:This creates a race condition between:
apt-daily/apt-daily-upgradeprocess.unattended-upgradecommand explicitly triggered by Ansible.A possible fix would be to either prevent both mechanisms from running at the same time or introduce an appropriate delay/wait for the package manager lock before retrying.
Changes
In playbooks/roles/security/tasks/security-ubuntu.yml:
New task: wait for the dpkg lock, then repair dpkg. It runs only when SECURITY_UPGRADE_ON_ANSIBLE is true.
Waits until no process holds the dpkg/apt lock files, giving up after 30 minutes.
Runs dpkg --configure -a to finish any interrupted package installs.
If the 30 minutes run out, it fails immediately with a clear error.
It always reports ok rather than changed.
delay: 30 on the existing retries. The 10 retries now cover about 5 minutes instead of about 50 seconds. This handles the background timer firing again between the wait and the upgrade.
Impact
Applies to every play that includes the security role (through common) with SECURITY_UPGRADE_ON_ANSIBLE enabled.
When nothing holds the lock, the new task adds only a second or two.
No new variables or defaults, and no changes needed in internal repos.
Needs fuser (from the psmisc package), which is on standard Ubuntu server and cloud images.
Testing
YAML parses
stage-xqueue pipeline re-run on this branch: "Wait for background apt/dpkg…" shows ok, and "Take security updates" passes without FAILED - RETRYING
Make sure that the following steps are done before merging: