← Back to issue list

fix: Avoid races with udev and loop devices

View original Github issue

Metadata

Project
imagecraft
Number
#340
Type
pull request
State
open
Author
mwhudson
Labels
Created
Updated
Closed

Current evaluation

Adds flock LOCK_EX on the whole-disk node during mkfs and across loop partition mounts to fix udev/loop-device races; supersedes #330's approach. Open 118 days with no review or comments; CI mostly green but lint, title policy, and snap-builds checks failing.

Suggested action: needs review

Reason: The PR has sat 118 days with zero maintainer interaction (0 reviewers, 0 comments) and three failing CI checks (lint / files, Conventional Commits title policy, snap-builds) that the author should address. It is not stale-irrelevant: the udev race it targets is still present in the codebase (services/image.py relies on a _wait_for_partition_nodes polling workaround, and the related #330 is still open with 6 unresolved comments), so a maintainer review of this alternative flock-based approach is warranted.

Impact: 45 Quick Win: 15.75 Staleness: 60 Complexity: 65 Confidence: 78

Issue body

- **fix(image): hold flock LOCK_EX on whole-disk node during mkfs** - **fix(chroot): hold flock LOCK_EX across mount(2) of loop partitions** I argued with Claude until it produced a better fix than #330. - [x] I've followed the [contribution guidelines](https://github.com/canonical/imagecraft/blob/main/CONTRIBUTING.md). - [x] I've signed the [CLA](http://www.ubuntu.com/legal/contributors/). - [x] I've successfully run `make lint && make test`. - [ ] I've added or updated any relevant documentation. - [ ] In documents I changed, I [added a meta description](https://canonical-starflow.readthedocs-hosted.com/how-to/add-a-page-meta-description/) if one was missing.

Evaluation history

Date Model Scores Action Summary
qwen/qwen3.8-27b
Impact: 45
Quick Win: 15.75
Staleness: 60
Complexity: 65
Confidence: 78
needs review Adds flock LOCK_EX on the whole-disk node during mkfs and across loop partition mounts to fix udev/loop-device races; supersedes #330's approach. Open 118 days with no review or comments; CI mostly green but lint, title policy, and snap-builds checks failing.
qwen/qwen3.6-35b-a3b
Staleness: 55
Complexity: 40
Confidence: 85
needs review Fixes race conditions with udev and loop devices by holding exclusive file locks during mkfs and loop partition mounts. Currently pending maintainer review with no comments, minor CI lint/policy failures, and 78 days of inactivity.
qwen3.6-35b-a3b-mtp-q6
Staleness: 50
Complexity: 45
Confidence: 75
needs review Fixes race conditions with udev and loop devices by holding exclusive file locks during mkfs and loop partition mounts. Currently awaiting maintainer review after 63 days of inactivity.
qwen3.6-35b-a3b-mtp-q6
Staleness: 45
Complexity: 65
Confidence: 75
needs review Fixes race conditions with udev and loop devices by adding exclusive file locks during mkfs and loop partition mounts. Currently awaiting maintainer review after 61 days of inactivity.
qwen3.6-35b-a3b-mtp-q6
Staleness: 45
Complexity: 40
Confidence: 75
needs review Fixes udev and loop device race conditions by applying exclusive file locks during mkfs and mount operations. Open for 42 days with zero comments. Linting and tests pass, but documentation updates are pending. Awaiting review and triage.

Update history

No update history recorded yet.

Related work

  • Related To: canonical/imagecraft#330 (confidence 85%)

    PR body explicitly cites #330 as the prior attempt ('a better fix than #330'); #330 is still open with 6 unresolved review comments, so this PR is a competing approach to the same udev/losetup race.

Related issues

Issue Project State Summary Similarity
#330 fix: synchronize with udev via BSD flock after losetup to avoid race condition imagecraft open Adds BSD flock synchronization after losetup to avoid the udev race on loop partition nodes, in both pack and services attach paths, with unit and root integration tests. Changes requested; 6 unresolved comments; lint/files failing; awaiting maintainer review of latest commit.
78%
#300 Race condition when mounting loop devices imagecraft open Race condition where loop partition devices (/dev/loopXpN) don't exist yet when mount is called after losetup --partscan. Triaged, maintainer suggested flock on parent device. Partial fix (wait for nodes) added in services/image.py via PR #428, but same failure still hit in pack path CI (19 days ago).
74%