Repository navigation
Detect and log stale package-manager lock holders during apt operations - #389
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #389 +/- ##
==========================================
+ Coverage 94.95% 94.98% +0.02%
==========================================
Files 113 113
Lines 21844 21936 +92
==========================================
+ Hits 20743 20835 +92
Misses 1101 1101
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Address sensitive command-line logging, truncated process output, locale-dependent parsing, and incomplete safety-test assertions.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
What changed in this PR
Adds detection-only diagnostics for apt lock contention, including holder PID, runtime, command line, and LinuxPatchExtension version comparison.
Changes:
- Detects and parses apt lock-holder failures.
- Logs extension ownership and version comparisons without taking recovery action.
- Adds tests for stale extension and unrelated lock holders.
| File | Summary |
|---|---|
src/core/tests/Test_AptitudePackageManager.py |
Tests stale and unrelated lock-holder scenarios. |
src/core/src/package_managers/AptitudePackageManager.py |
Implements lock-holder inspection and structured warnings. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
3e74a8d
This release contains: 1. Address Pending Comments from Dnf5 Original PR: #355 2. Feature: Sanitize credential-like URLs in telemetry events to avoid False CredScan detection : #340 3. [UEFI] Handling error code 2 for fwupgmgr refresh : #382 4. Flaky UT Fix: #380 5. Bugfix: Fix Failing UT missing credential sanitizer: #376 6. Fundamentals: Automatically request reviewers- #375 7. Bugfix: Fix Failing UT missing credential sanitizer : #374 8. Bugfix: Validate that process is actually a patching operation before terminating: #367 9. Feature: Adding Rhel10 Base Support using dnf4 package manager: #359 10. BugFix for DNF5: Exclusion list not honored: #357 11. Detect and log stale package-manager lock holders during apt operations: #389

Issue:
Multiple VM's are failing patch assessments repeatedly with apt-get update returning exit code 100:
Root cause
A stale apt-get process spawned by an older LinuxPatchExtension version (e.g. v1.6.x) kept holding the apt lock for 70+ days and was never cleaned up after the extension upgraded (e.g. to v1.6.x1). Every subsequent assessment failed. Recovery required manual intervention (kill the process, remove the lock, re-run) on each VM.
Per maintainer guidance, we do not automatically clear package-manager locks (risky, can interfere with legitimate operations). The first step is detection + telemetry/logging only, so we can confirm the "orphaned, extension-owned, older-version" scenario in the field before considering any scoped, safe recovery later.
What the PR does
In AptitudePackageManager.invoke_package_manager_advanced, on the existing failure branch:
TESTING
Manual end-to-end on a VM (Ubuntu 24.04, current build 1.6.72):
ARM : /subscriptions/6acc8a91-e2b0-4041-a069-c2932ab42fd9/resourceGroups/apt_lock_issue_rg/providers/Microsoft.Compute/virtualMachines/apt-lock-vm-ubuntu
`cat > /tmp/hold_apt_lock.py <<'EOF'
import fcntl, time
f = open('/var/lib/apt/lists/lock', 'w')
fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB) # POSIX lock apt's F_GETLK can see
time.sleep(3600)
EOF
sudo python3 /tmp/hold_apt_lock.py
-oDir::Etc::SourceParts=/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.6.64/tmp/azgps-src &`
Confirmed apt reports the holder PID
sudo apt-get -q update # => E: Could not get lock ... It is held by process <pid> (python3) ps -p <pid> -o pid=,etime=,cmd= # cmdline shows the LinuxPatchExtension-1.6.64 pathTriggered an assessment while the lock was held.
Verified the detection line appeared on every retry, with HolderVersion=1.6.64, CurrentVersion=1.6.72, IsOlderVersion=True, and that no process was killed and no lock removed (assessment failed/retried normally).
3.core.log
New log after recent change: ( September 23rd)
5.core.log