← Back to issue list

Race condition when mounting loop devices

View original Github issue

Metadata

Project
imagecraft
Number
#300
Type
issue
State
open
Author
lengau
Labels
Status: Triaged Type: Bug
Created
2026-03-23 15:46:04+00:00
Updated
2026-04-21 22:07:28+00:00
Closed

Current evaluation

Triaged bug causing mount failures when loop partitions are accessed before udev processing completes, currently awaiting implementation of a proposed flock-based fix.

Suggested action: keep open

Reason: The issue is already triaged and has clear maintainer buy-in with a specific technical hypothesis and suggested fix. It is a valid bug ready for implementation, so it should remain open for a contributor to address.

Staleness: 25 Complexity: 45 Support Request: 0

Issue body

### Check existing issues - [x] I've verified that this bug isn't described by any existing issues. ### Bug description Discovered and researched by @smethnani. When we create loop devices, there's a race condition we sometimes hit when trying to mount them before they fully exist. The upstream version of this bug is in https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/2045586 ### Steps to reproduce n/a it's a race condition ### Environment We need to understand the context in which Imagecraft failed. Please let us know if you are running Imagecraft in destructive mode, whether you are using LXD or Multipass, and which operating system you are running Imagecraft on. ### imagecraft.yaml ```yaml ``` ### Log output ```shell See: https://github.com/canonical/imagecraft/actions/runs/23426535878/job/68143721209?pr=289#step:9:196 Getting partition table Adding partition volume/pc/data3 to the image Setting up GRUB in the image mount: /home/imagecraft/tests/spread/pack/complex/mount: special device /dev/loop7p2 does not exist. dmesg(1) may have more information after failed mount system call. mount: /home/imagecraft/tests/spread/pack/complex/mount: mount failed: Unknown error 5005. Failed to clean chroot Detailed information: Command '['/bin/mount', '/home/imagecraft/tests/spread/pack/complex/mount', '--make-rprivate']' returned non-zero exit status 32. Full execution log: '/root/.local/state/imagecraft/log/imagecraft-20260323-081704.190556.log' ----- . 2026-03-23 08:17:22 Debug output for google:ubuntu-24.04-64:tests/spread/pack/complex (mar230753-821890) : ----- ++ find /root/.local/state/imagecraft/log/ -name 'imagecraft*.log' ++ sort -n ++ tail -n1 + imagecraft_log_file=/root/.local/state/imagecraft/log/imagecraft-20260323-081704.190556.log [...] 2026-03-23 08:17:21.218 Getting partition table 2026-03-23 08:17:21.218 Running command: ['sfdisk', '--json', 'pc.img'] 2026-03-23 08:17:21.222 Adding partition volume/pc/data3 to the image 2026-03-23 08:17:21.286 Running command: ['sfdisk', '--json', 'pc.img'] 2026-03-23 08:17:21.289 Setting up GRUB in the image 2026-03-23 08:17:21.289 Running command: ['losetup', '--find', '--show', '--partscan', 'pc.img'] 2026-03-23 08:17:21.313 Attached image pc.img as loop device /dev/loop7 2026-03-23 08:17:21.314 [pid=57966] parent process 2026-03-23 08:17:21.314 [pid=57966] set up chroot 2026-03-23 08:17:21.314 setup chroot: PosixPath('/home/imagecraft/tests/spread/pack/complex/mount') 2026-03-23 08:17:21.314 [pid=57966] mount '/home/imagecraft/tests/spread/pack/complex/mount' on chroot 2026-03-23 08:17:21.315 mount device='/dev/loop7p2', mountpoint='/home/imagecraft/tests/spread/pack/complex/mount', args=() 2026-03-23 08:17:21.318 [pid=57966] clean up chroot 2026-03-23 08:17:21.318 cleanup chroot: PosixPath('/home/imagecraft/tests/spread/pack/complex/mount') 2026-03-23 08:17:21.318 [pid=57966] umount: '/home/imagecraft/tests/spread/pack/complex/mount' 2026-03-23 08:17:21.318 mount device='/home/imagecraft/tests/spread/pack/complex/mount', mountpoint='--make-rprivate', args=() 2026-03-23 08:17:21.321 Running command: ['losetup', '--json'] 2026-03-23 08:17:21.325 Detaching loop device /dev/loop7 (from /home/imagecraft/tests/spread/pack/complex/pc.img) 2026-03-23 08:17:21.325 Running command: ['losetup', '-d', '/dev/loop7'] 2026-03-23 08:17:21.327 Failed to clean chroot 2026-03-23 08:17:21.327 Detailed information: Command '['/bin/mount', '/home/imagecraft/tests/spread/pack/complex/mount', '--make-rprivate']' returned non-zero exit status 32. 2026-03-23 08:17:21.328 Full execution log: '/root/.local/state/imagecraft/log/imagecraft-20260323-081704.190556.log' ```

Evaluation history

Date Model Scores Action Summary
2026-06-01 11:45:21.993706+00:00 qwen3.6-35b-moe-q4
Staleness: 25
Complexity: 45
Support Request: 0
keep open Triaged bug causing mount failures when loop partitions are accessed before udev processing completes, currently awaiting implementation of a proposed flock-based fix.
2026-06-01 11:40:57.408888+00:00 pending