Skip to content

fix(installer): bound the apt dpkg-lock wait so a held lock can't hang the install (#210) - #211

Merged
saadqbal merged 1 commit into
developfrom
fix/210-installer-apt-lock-hang
Jun 6, 2026
Merged

fix(installer): bound the apt dpkg-lock wait so a held lock can't hang the install (#210)#211
saadqbal merged 1 commit into
developfrom
fix/210-installer-apt-lock-hang

Conversation

@saadqbal

@saadqbalsaadqbal commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Fixes#210. Complementary to #212 (now merged) — that PR fixed the needrestart hidden-prompt hang; this one fixes the dpkg-lock hang. Same symptom (Installing conntrack… freezes on a fresh Ubuntu host), different root cause.

Rebased onto develop after #212 merged, so the diff is the lock dimension only.

Root cause

On a freshly-booted host, apt-daily / unattended-upgrades hold the dpkg lock. The installer's apt-get install had no lock timeout, so it waited indefinitely — and spin_cmd redirects apt's Waiting for cache lock… line into a log file, so it looked frozen with no error.

What this adds (on top of #212)

  • setup_pm: add -o DPkg::Lock::Timeout=600 to the apt update/install commands → bounded wait, then a clear failure (which spin_cmd surfaces) instead of an infinite silent hang. Appends to fix(installer): keep apt non-interactive so needrestart can't hang installs on Ubuntu 22.04+ #212's non-interactive sudo env command, leaving its env exactly as-is.
  • New apt_wait_for_lock: a visible, bounded Waiting for background system updates to finish… spinner before the docker / system-deps installs (no-op when apt or fuser is absent, or the lock is free). Placed before install_docker_engine so the get.docker.com apt path benefits too.
  • setup-linux.bats: assert both apt commands carry the lock timeout (regression guard).

Testing

  • bash -n scripts/lib/setup-linux.sh — clean.
  • Sourced the real setup_pm / apt_wait_for_lock with the bats mocks and asserted fix(installer): keep apt non-interactive so needrestart can't hang installs on Ubuntu 22.04+ #212's guarantees (sudo env, DEBIAN_FRONTEND=noninteractive, NEEDRESTART_MODE=a) and this PR's (DPkg::Lock::Timeout= in both apt commands) hold together; dnf branch free of the apt option; apt_wait_for_lock no-ops on the no-fuser / lock-free paths. All pass.
  • bats isn't installed locally — the cross-distro installer CI exercises the real path.

Compatibility

DPkg::Lock::Timeout is a config key (-o), unknown to pre-2.0 apt (e.g. 18.04) where it's silently ignored — no breakage on older distros. dnf/yum/zypper/pacman branches unchanged.

Immediate client workaround (no merge needed)

while sudo fuser /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock >/dev/null 2>&1;doecho"waiting for apt lock…"; sleep 5;done# then re-run the installer

🤖 Generated with Claude Code


Note

Low Risk
Linux installer script and test-only changes; no auth, data, or runtime service logic affected.

Overview
Fixes #210: on fresh Debian/Ubuntu boots, apt-daily / unattended-upgrades can hold the dpkg lock while the Linux installer runs apt behind spin_cmd, so the install looks frozen (e.g. at “Installing conntrack…”) with no visible “Waiting for cache lock…” message.

setup_pm now passes -o DPkg::Lock::Timeout=600 on apt update and install so lock waits are bounded and failures surface instead of hanging silently. A new apt_wait_for_lock runs early in install_linux (before Docker/system deps): if fuser sees holders on the standard lock paths, it shows a “Waiting for background system updates to finish…” spinner for up to 600s; otherwise it no-ops. Non-apt package managers are unchanged. setup-linux.bats asserts both apt commands include the lock timeout.

Reviewed by Cursor Bugbot for commit 2481d41. Bugbot is set up for automated code reviews on this repo. Configure here.

@saadqbalsaadqbal self-assigned this Jun 5, 2026
@LukasWodka

Copy link
Copy Markdown
Contributor

👋 Heads-up — Code review queue is at 17 / 8

Above the WIP limit. The team convention is to review existing PRs before opening new work.

Open PRs currently in Code review (oldest first):

Pull from review before opening new work. (This is a nudge from the kanban WIP check, not a block.)

@saadqbal
saadqbalforce-pushed the fix/210-installer-apt-lock-hang branch from 32b1d87 to 8d819ccCompareJune 5, 2026 15:14
@saadqbalsaadqbal changed the title fix(installer): bound apt lock wait so 'Installing conntrack…' can't hang forever (#210)fix(installer): bound the apt dpkg-lock wait so a held lock can't hang the install (#210)Jun 5, 2026
@saadqbal
saadqbal changed the base branch from develop to fix/conntrack-ubuntu-noninteractiveJune 5, 2026 15:15
…g the install (#210)
Stacked on #212 (the needrestart non-interactive fix). This adds the lock
dimension #212 doesn't cover: on a freshly-booted Ubuntu, apt-daily /
unattended-upgrades hold the dpkg lock and apt-get waits on it forever —
and spin_cmd hides apt's "Waiting for cache lock" line, so it looks frozen.
- setup_pm: add -o DPkg::Lock::Timeout=600 to the apt update/install commands
so the wait is bounded and fails with a clear error instead of hanging.
- add apt_wait_for_lock: a visible, bounded "Waiting for background system
updates to finish…" step before the docker / system-deps installs.
- bats: assert the apt commands carry the lock timeout.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@saadqbal
saadqbalforce-pushed the fix/210-installer-apt-lock-hang branch from 8d819cc to 2481d41CompareJune 5, 2026 16:41
@saadqbal
saadqbal changed the base branch from fix/conntrack-ubuntu-noninteractive to developJune 5, 2026 16:42
@saadqbal
saadqbal requested a review from LukasWodkaJune 5, 2026 16:44
@saadqbalsaadqbal closed this Jun 5, 2026
@saadqbalsaadqbal reopened this Jun 5, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't workingwork-type:bugDefect or regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@saadqbal@LukasWodka