lxc fails to create containers concurrently
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxc (Ubuntu) |
Fix Released
|
Low
|
Serge Hallyn | ||
Precise |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
========== SRU justification ==============
1. Impact: parallel creations of containers with the same template
will result in all but one failing. They should instead run in
parallel without racing in their critical section.
2. Development fix: don't add '-n' to the flock arguments, which causes
flock to fail instead of waiting.
3. Stable fix: same as development fix.
4 Test case:
for i in `seq 10 12`; do
screen -d -m sudo lxc-create -t ubuntu -n p$i
done
ret=0
while [ $ret -eq 0 ]; do
sleep 1
pidof bash > /dev/null 2>&1
ret=$?
done
while [ `pidof lxc-create > /dev/null 2>&1` ]; do
sleep 1
done
lxc-ls
# make sure p10, p11, and p12 exist
5. Regression potential: none
=======
When multiple containers (template ubuntu) are created simultaneously only the first container is successfully created, others fail with "failed to execute template 'ubuntu'"
This is a very common scenario in automated tests.
TEST CASE:
Run the following script with sudo
"""
#!/bin/sh
MAX=3
echo "Destroying existing containers"
for x in $(seq 1 $MAX); do
sudo lxc-destroy -f -n test-lxc-$x &
done
sleep 10
sudo lxc-list
echo "Creating $MAX ubuntu containers"
for x in $(seq 1 $MAX); do
echo -n "Creating $x ..."
sudo lxc-create -t ubuntu -n test-lxc-$x &
echo "done"
done
echo "Waiting 30s for test to finish"
sleep 30
sudo lxc-list
"""
ACTUAL RESULT
=======
$ sudo sh ./lxc-create-
Destroying existing containers
'test-lxc-1' does not exist
'test-lxc-2' does not exist
'test-lxc-3' does not exist
RUNNING
FROZEN
STOPPED
Creating 3 ubuntu containers
Creating 1 ...done
Creating 2 ...done
Creating 3 ...done
Waiting 30s for test to finish
No config file specified, using the default config
No config file specified, using the default config
No config file specified, using the default config
debootstrap is /usr/sbin/
debootstrap is /usr/sbin/
Checking cache download in /var/cache/
Copy /var/cache/
Copying rootfs to /var/lib/
failed to execute template 'ubuntu'
debootstrap is /usr/sbin/
failed to execute template 'ubuntu'
aborted
aborted
##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##
'ubuntu' template installed
'test-lxc-1' created
RUNNING
FROZEN
STOPPED
test-lxc-1
=======
ProblemType: Bug
DistroRelease: Ubuntu 12.10
Package: lxc 0.8.0~rc1-4ubuntu10
ProcVersionSign
Uname: Linux 3.4.0-3-generic x86_64
ApportVersion: 2.1.1-0ubuntu1
Architecture: amd64
Date: Fri Jun 1 17:32:06 2012
ProcEnviron:
TERM=xterm
PATH=(custom, user)
LANG=en_US.UTF-8
SHELL=/bin/bash
SourcePackage: lxc
UpgradeStatus: Upgraded to quantal on 2012-01-31 (121 days ago)
Changed in lxc (Ubuntu): | |
assignee: | nobody → Serge Hallyn (serge-hallyn) |
status: | Confirmed → In Progress |
description: | updated |
The download_ubuntu function does 'flock -n -x 200'. Removing the -n should make the parallel lxc-creates block rather than exit with failure.