ec2: zesty tempfile sandbox dhclient.pid file can't be created
| Affects | Status | Importance | Assigned to | Milestone | |
|---|---|---|---|---|---|
| cloud-init |
Fix Released
|
High
|
Chad Smith | ||
| cloud-init (Ubuntu) |
Fix Released
|
Medium
|
Unassigned | ||
| Xenial |
Fix Released
|
Medium
|
Unassigned | ||
| Zesty |
Fix Released
|
Medium
|
Unassigned | ||
| Artful |
Fix Released
|
Medium
|
Unassigned | ||
| Bionic |
Fix Released
|
Medium
|
Unassigned | ||
Bug Description
=== Begin SRU Template ===
[Impact]
Ec2 instances could hit race condition with tempdir removal where dhclient doesn't write a pidfile and DataSourceEc2Local hits a traceback trying to read that non-existent pidfile. This traceback causes the instance to fallback and get discovered in init-network stage as DataSourceEc2. The thrashing costs instances a couple extra seconds to boot while re-discovering in a different stage.
[Test Case]
# Launch instance under test
$ for release in xenial zesty artful; do
echo "Handling $release";
launch-ec2 --series $release;
ssh ubuntu@
ssh ubuntu@
ssh ubuntu@
ssh ubuntu@
ssh ubuntu@
# Show upgrade without restart doesn't break
ssh ubuntu@
# Show clean install doesn't break
ssh ubuntu@
ssh ubuntu@
ssh ubuntu@
# Asssert no intermittent tracebacks from dhcp_discovery and no leaked dhcpclients;
ssh ubuntu@
sudo ps -afe |grep dhclient;
done
[Regression Potential]
Regression would still result in Tracebacks in DataSourceEc2Local which would cause cloud-init to fallback to DataSourceEc2 in init-network stage.
[Other Info]
Upstream commit at
https:/
=== End SRU Template ===
=== Original Description ===
Saw an issue once on EC2 zesty image with 17.1.41 during SRU testing.
Looks like we hit an inability to create the pid file (from syslog)
#### syslog
Nov 30 04:20:35 ip-10-0-20-176 cloud-init[440]: Cloud-init v. 17.1 running 'init-local' at 2017年11月30日 04:20:32 +0000. Up 7.16 seconds.
Nov 30 04:20:35 ip-10-0-20-176 cloud-init[440]: 2017年11月30日 04:20:32,768 - util.py[WARNING]: Getting data from <class 'cloudinit.
Nov 30 04:20:35 ip-10-0-20-176 dhclient[669]: Can't create /var/tmp/
#### end syslog
A traceback when trying to read the temporary pid file that was created by our dhclient run during Ec2Local setup. Maybe we exited out of the dhcp run before we could read the pid file?
...
2017年11月30日 04:20:32,738 - util.py[DEBUG]: Running command ['ip', 'link', 'set', 'dev', 'eth0', 'up'] with allowed return codes [0] (shell=False, capture=True)
2017年11月30日 04:20:32,744 - util.py[DEBUG]: Running command ['/var/
2017年11月30日 04:20:32,768 - util.py[DEBUG]: Reading from /var/tmp/
2017年11月30日 04:20:32,768 - handlers.py[DEBUG]: finish: init-local/
2017年11月30日 04:20:32,768 - util.py[WARNING]: Getting data from <class 'cloudinit.
2017年11月30日 04:20:32,768 - util.py[DEBUG]: Getting data from <class 'cloudinit.
Traceback (most recent call last):
File "/usr/lib/
if s.get_data():
File "/usr/lib/
return super(DataSourc
File "/usr/lib/
self.
File "/usr/lib/
return dhcp_discovery(
File "/usr/lib/
pid = int(util.
File "/usr/lib/
with open(fname, 'rb') as ifh:
FileNotFoundError: [Errno 2] No such file or directory: '/var/tmp/
Related branches
- Server Team CI bot: Approve (continuous-integration)
- Scott Moser: Pending requested
-
Diff: 667 lines (+221/-77) 15 files modifiedapicloudinit/net/dhcp.py (+29/-15)
cloudinit/net/network_state.py (+8/-0)
cloudinit/net/sysconfig.py (+15/-0)
cloudinit/net/tests/test_dhcp.py (+61/-5)
cloudinit/sources/DataSourceAzure.py (+3/-26)
cloudinit/util.py (+22/-0)
debian/changelog (+13/-0)
tests/cloud_tests/images/nocloudkvm.py (+15/-7)
tests/cloud_tests/instances/nocloudkvm.py (+5/-3)
tests/cloud_tests/platforms/nocloudkvm.py (+11/-10)
tests/cloud_tests/releases.yaml (+16/-0)
tests/cloud_tests/setup_image.py (+3/-3)
tests/cloud_tests/snapshots/nocloudkvm.py (+11/-6)
tests/unittests/test_datasource/test_azure.py (+3/-2)
tests/unittests/test_net.py (+6/-0)
- Server Team CI bot: Approve (continuous-integration)
- Scott Moser: Pending requested
-
Diff: 667 lines (+221/-77) 15 files modifiedapicloudinit/net/dhcp.py (+29/-15)
cloudinit/net/network_state.py (+8/-0)
cloudinit/net/sysconfig.py (+15/-0)
cloudinit/net/tests/test_dhcp.py (+61/-5)
cloudinit/sources/DataSourceAzure.py (+3/-26)
cloudinit/util.py (+22/-0)
debian/changelog (+13/-0)
tests/cloud_tests/images/nocloudkvm.py (+15/-7)
tests/cloud_tests/instances/nocloudkvm.py (+5/-3)
tests/cloud_tests/platforms/nocloudkvm.py (+11/-10)
tests/cloud_tests/releases.yaml (+16/-0)
tests/cloud_tests/setup_image.py (+3/-3)
tests/cloud_tests/snapshots/nocloudkvm.py (+11/-6)
tests/unittests/test_datasource/test_azure.py (+3/-2)
tests/unittests/test_net.py (+6/-0)
- Server Team CI bot: Approve (continuous-integration)
- Scott Moser: Pending requested
-
Diff: 667 lines (+221/-77) 15 files modifiedapicloudinit/net/dhcp.py (+29/-15)
cloudinit/net/network_state.py (+8/-0)
cloudinit/net/sysconfig.py (+15/-0)
cloudinit/net/tests/test_dhcp.py (+61/-5)
cloudinit/sources/DataSourceAzure.py (+3/-26)
cloudinit/util.py (+22/-0)
debian/changelog (+13/-0)
tests/cloud_tests/images/nocloudkvm.py (+15/-7)
tests/cloud_tests/instances/nocloudkvm.py (+5/-3)
tests/cloud_tests/platforms/nocloudkvm.py (+11/-10)
tests/cloud_tests/releases.yaml (+16/-0)
tests/cloud_tests/setup_image.py (+3/-3)
tests/cloud_tests/snapshots/nocloudkvm.py (+11/-6)
tests/unittests/test_datasource/test_azure.py (+3/-2)
tests/unittests/test_net.py (+6/-0)
- Server Team CI bot: Approve (continuous-integration)
- Scott Moser: Approve
-
Diff: 320 lines (+118/-48) 5 files modifiedapicloudinit/net/dhcp.py (+29/-15)
cloudinit/net/tests/test_dhcp.py (+61/-5)
cloudinit/sources/DataSourceAzure.py (+3/-26)
cloudinit/util.py (+22/-0)
tests/unittests/test_datasource/test_azure.py (+3/-2)
- cloud-init.log Edit (109.4 KiB, text/plain)
cloud-init log from Ec2Local failure to read dhclient.pid file
More detail:
this also happens on previous 17.1.27, we just never tried to read that pidfile to act on it.
Nov 30 04:54:32 ip-10-0-20-176 dhclient[683]: Can't create /var/tmp/
Validated it doesn't happen on Artful. with 17.1.27 or 17.1.41
+ ec2: zesty tempfile sandbox dhclient.pid file can't be created
In further testing it is a timing thing with our tempdirectory being removed before dhclient attempts to write the actual pidfile.
sudo python3 -c 'from cloudinit.net.dhcp import maybe_perform_
This fails 100% of the time in zesty and artful emitting "Can't create dhclient[3296]: Can't create /var/tmp/
If I add a sleep(0.000001) in cloudinit/
Alternatively we could just have a busy wait there and only exit the tempdir context once we know we have a pid file and can clean ourselves up.
while not os.path.
pass
This affectively causes Ec2Local to fail and we fall back to Ec2 in the init-network stage. It slows down ec2 instance boots a bit, but cloud-init will still function on ec2.
OK. So dhclient is fun.
Background info
* we run dhclient like this:
-1 (try to get an ip address only once exit fail on fail).
-v (verbose)
-lf <tmpdir>
-pf <tmpdir>/pid
<interface>
-sf /bin/true
* dhclient.c source [1]
I'm pretty sure this is what is happening here.
1. when daemonizing, dhclient does not write its pidfile immediately (line 971). Instead it waits until it does "go_daemon" (line 4203). This does make some sense as it goes daemon by forking and the new process staying around.
2. on successful acquisition of address, cloud-init is removing the temp dir and looking for the pid before the fork()'ed process writes it.
2a. on failure, i think a pid is probably not written at all. I don't think we're handling the possible ProcessExecutio
Heres a suggestion for a fix
http://
Another option would be for cloud-init to invoke dhclient with '-d' (do not background) which would avoid the background process entirely. The '-1' would allow it to exit on failure. Then on success we'd have to have the script file signal somehow that it was done or possibly just kill its parent.
The last option of course is to write a dhcp client in python :), which is looking more and more appealing.
[1] https:/
Interesting thing smoser is that dhclient doesn't actually return an error code where there are problems. Not the following when I hit selinux issues with /sbin/dhclient instead of our /tmp/dhclient
http://
>>> from cloudinit.util import subp
>>> subp(['sudo', '/sbin/dhclient', '-1', '-v', '-lf', '/home/
('', "Internet Systems Consortium DHCP Client 4.3.3\nCopyright 2004-2015 Internet Systems Consortium.\nAll rights reserved.\nFor info, please visit https:/
Even parsing error output isn't an option (although we could catch SELinux type errors) because dhclient doesn't emit the 'Can't create pidfile' message until after the background process was forked.
So, I'll take part of your suggested patch, but I think us parsing or try/except handling of subp output is going to end up fruitless in this or other cases as dhclient doesn't really seem to exit in error upon the errors we care about.
This bug was fixed in the package cloud-init - 17.1-46-
---------------
cloud-init (17.1-46-
* New upstream snapshot.
- ec2: Fix sandboxed dhclient background process cleanup.
[Chad Smith] (LP: #1735331)
- tests: NoCloudKVMImage do not modify the original local cache image.
- tests: Enable bionic in integration tests. [Joshua Powers]
- tests: Use apt-get to install a deb so that depends get resolved.
- sysconfig: Correctly render dns and dns search info.
[Ryan McCabe] (LP: #1705804)
-- Scott Moser <email address hidden> 2017年11月30日 21:59:55 -0500
An upload of cloud-init to artful-proposed has been rejected from the upload queue for the following reason: "to reupload with -v".
Hello Chad, or anyone else affected,
Accepted cloud-init into artful-proposed. The package will build now and be available at https:/
Please help us by testing this new package. See https:/
If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-
Further information regarding the verification process can be found at https:/
Hello Chad, or anyone else affected,
Accepted cloud-init into zesty-proposed. The package will build now and be available at https:/
Please help us by testing this new package. See https:/
If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-
Further information regarding the verification process can be found at https:/
- ec2-sru-validate-17.1.46.log Edit (16.0 KiB, text/plain)
Thanks Steve. Attached are the verification logs for ec2 instance asserting that this bug is fixed.
# Launch instance under test
$ for release in xenial zesty artful; do
echo "Handling $release";
launch-ec2 --series $release;
ssh ubuntu@
ssh ubuntu@
ssh ubuntu@
ssh ubuntu@
ssh ubuntu@
# Show upgrade without restart doesn't break
ssh ubuntu@
# Show clean install doesn't break
ssh ubuntu@
ssh ubuntu@
ssh ubuntu@
# Asssert no intermittent tracebacks from dhcp_discovery and no leaked dhcpclients;
ssh ubuntu@
sudo ps -afe |grep dhclient;
done
[Regression Potential]
Regression would still result in Tracebacks in DataSourceEc2Local which would cause cloud-init to fallback to DataSourceEc2 in init-network stage.
[Other Info]
Upstream commit at
https:/
=== End SRU Template ===
=== SRU Verification output ===
### EC2 Xenial upgrade and fresh install test
ubuntu@
ubuntu@
...
ubuntu@
{
"v1": {
"datasource": "DataSourceEc2L
"errors": []
}
}
ubuntu@
ubuntu@
Setting up cloud-init (17.1-46-
ubuntu@
Cloud-init v. 17.1 running 'init' at 2017年12月02日 04:10:13 +0000. Up 167.09 seconds.
ci-info: +++++++
ci-info: +------
ci-info: | Device | Up | Address | Mask | Scope | Hw-Address |
ci-info: +------
ci-info: | eth0 | True | 10.0.20.54 | 255.255.255.0 | . | 0a:a4:58:cb:62:8c |
ci-info: | eth0 | True | 2600:1f16:
ci-info: | lo | True | 127.0.0.1 | 255.0.0.0 | . | . |
ci-info: | lo | True | ::1/128 | . | host | . |
ci-info: +------
ci-info: +++++++
removed: verification-needed verification-needed-artful verification-needed-zesty
This bug was fixed in the package cloud-init - 17.1-46-
---------------
cloud-init (17.1-46-
* New upstream snapshot.
- ec2: Fix sandboxed dhclient background process cleanup.
(LP: #1735331)
- tests: NoCloudKVMImage do not modify the original local cache image.
- tests: Enable bionic in integration tests. [Joshua Powers]
- tests: Use apt-get to install a deb so that depends get resolved.
- sysconfig: Correctly render dns and dns search info.
[Ryan McCabe]
cloud-init (17.1-41-
* debian/
(LP: #1728186)
* New upstream snapshot (LP: #1733653)
- integration test: replace curtin test ppa with cloud-init test ppa.
- EC2: Fix bug using fallback_nic and metadata when restoring from cache.
- EC2: Kill dhclient process used in sandbox dhclient.
- ntp: fix configuration template rendering for openSUSE and SLES
- centos: Provide the failed #include url in error messages
- Catch UrlError when #include'ing URLs [Andrew Jorgensen]
- hosts: Fix openSUSE and SLES setup for /etc/hosts and clarify docs.
[Robert Schweikert]
- rh_subscription: Perform null checks for enabled and disabled repos.
[Dave Mulford]
- Improve warning message when a template is not found.
[Robert Schweikert]
- Replace the temporary i9n.brickies.net with i9n.cloud-init.io.
- Azure: don't generate network configuration for SRIOV devices
- tests: address some minor feedback missed in last merge.
- tests: integration test cleanup and full pass of nocloud-kvm.
- Gentoo: chmod +x on all files in sysvinit/gentoo/
[Carlos Konstanski]
-- Chad Smith <email address hidden> 2017年12月01日 10:05:01 -0700
The verification of the Stable Release Update for cloud-init has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.
This bug was fixed in the package cloud-init - 17.1-46-
---------------
cloud-init (17.1-46-
* New upstream snapshot.
- ec2: Fix sandboxed dhclient background process cleanup.
(LP: #1735331)
- tests: NoCloudKVMImage do not modify the original local cache image.
- tests: Enable bionic in integration tests. [Joshua Powers]
- tests: Use apt-get to install a deb so that depends get resolved.
- sysconfig: Correctly render dns and dns search info.
[Ryan McCabe]
cloud-init (17.1-41-
* debian/
(LP: #1728186)
* New upstream snapshot (LP: #1733653)
- integration test: replace curtin test ppa with cloud-init test ppa.
- EC2: Fix bug using fallback_nic and metadata when restoring from cache.
- EC2: Kill dhclient process used in sandbox dhclient.
- ntp: fix configuration template rendering for openSUSE and SLES
- centos: Provide the failed #include url in error messages
- Catch UrlError when #include'ing URLs [Andrew Jorgensen]
- hosts: Fix openSUSE and SLES setup for /etc/hosts and clarify docs.
[Robert Schweikert]
- rh_subscription: Perform null checks for enabled and disabled repos.
[Dave Mulford]
- Improve warning message when a template is not found.
[Robert Schweikert]
- Replace the temporary i9n.brickies.net with i9n.cloud-init.io.
- Azure: don't generate network configuration for SRIOV devices
- tests: address some minor feedback missed in last merge.
- tests: integration test cleanup and full pass of nocloud-kvm.
- Gentoo: chmod +x on all files in sysvinit/gentoo/
[Carlos Konstanski]
-- Chad Smith <email address hidden> 2017年12月01日 10:02:24 -0700
This bug was fixed in the package cloud-init - 17.1-46-
---------------
cloud-init (17.1-46-
* New upstream snapshot.
- ec2: Fix sandboxed dhclient background process cleanup.
(LP: #1735331)
- tests: NoCloudKVMImage do not modify the original local cache image.
- tests: Enable bionic in integration tests. [Joshua Powers]
- tests: Use apt-get to install a deb so that depends get resolved.
- sysconfig: Correctly render dns and dns search info.
[Ryan McCabe]
cloud-init (17.1-41-
* debian/
(LP: #1728186)
* New upstream snapshot (LP: #1733653)
- integration test: replace curtin test ppa with cloud-init test ppa.
- EC2: Fix bug using fallback_nic and metadata when restoring from cache.
- EC2: Kill dhclient process used in sandbox dhclient.
- ntp: fix configuration template rendering for openSUSE and SLES
- centos: Provide the failed #include url in error messages
- Catch UrlError when #include'ing URLs [Andrew Jorgensen]
- hosts: Fix openSUSE and SLES setup for /etc/hosts and clarify docs.
[Robert Schweikert]
- rh_subscription: Perform null checks for enabled and disabled repos.
[Dave Mulford]
- Improve warning message when a template is not found.
[Robert Schweikert]
- Replace the temporary i9n.brickies.net with i9n.cloud-init.io.
- Azure: don't generate network configuration for SRIOV devices
- tests: address some minor feedback missed in last merge.
- tests: integration test cleanup and full pass of nocloud-kvm.
- Gentoo: chmod +x on all files in sysvinit/gentoo/
[Carlos Konstanski]
-- Chad Smith <email address hidden> 2017年12月01日 09:58:48 -0700
This bug is believed to be fixed in cloud-init in 1705804. If this is still a problem for you, please make a comment and set the state back to New
Thank you.
We are seeing errors very similar to this:
can't create /var/tmp/
The /var/tmp/cloud-init has been created, world writable.
Started seeing the errors a few days after the fix was released - around 5th December.
AWS EC2
ubuntu 16.04.1
cloud-init 17.1-46-
Stretch, can you please attach /var/log/
Better would be to attach output of 'cloud-init collect-logs'
Thanks.
Tracked in Github Issues as https:/