From 430349ff0571aca12bc767ea3679b145695c1543 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Thu, 7 Apr 2016 16:39:51 -0500 Subject: [PATCH] institute better timeouts for metadata wgets, LP: #1564320 --- debian/changelog | 1 + usr/lib/byobu/ec2_cost | 4 ++-- usr/lib/byobu/hostname | 5 ++--- usr/lib/byobu/include/shutil | 2 +- usr/lib/byobu/ip_address | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/debian/changelog b/debian/changelog index e8756119..ac26bc2b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -14,6 +14,7 @@ byobu (5.105) unreleased; urgency=medium - fix color comment * usr/bin/byobu-janitor.in: - no longer default to enabling ec2 status, LP: #1564320 + - institute better timeouts for metadata wgets, LP: #1564320 [ Mark King ] * usr/lib/byobu/battery: diff --git a/usr/lib/byobu/ec2_cost b/usr/lib/byobu/ec2_cost index 8ff454de..b83f9f9a 100755 --- a/usr/lib/byobu/ec2_cost +++ b/usr/lib/byobu/ec2_cost @@ -37,11 +37,11 @@ __ec2_cost() { read rate < "$cache.rate" elif metadata_available; then # Try to use metadata service - [ -s "$cache.zone" ] || wget -q -O- http://169.254.169.254/latest/meta-data/placement/availability-zone "$cache.zone" 2>/dev/null & + [ -s "$cache.zone" ] || timeout 0.2 wget -q -O- http://169.254.169.254/latest/meta-data/placement/availability-zone "$cache.zone" 2>/dev/null & sleep 0.02 [ -s "$cache.zone" ] && read zone < "$cache.zone" zone=${zone%%[a-z]} - [ -s "$cache.type" ] || wget -q -O- http://169.254.169.254/latest/meta-data/instance-type "$cache.type" 2>/dev/null & + [ -s "$cache.type" ] || timeout 0.2 wget -q -O- http://169.254.169.254/latest/meta-data/instance-type "$cache.type" 2>/dev/null & sleep 0.02 [ -s "$cache.type" ] && read type < "$cache.type" $BYOBU_PREFIX/lib/byobu/include/ec2instancespricing.py --type ondemand --filter-region $zone --filter-type $type --filter-os-type linux --format csv | tail -n1 > "$cache.rate" diff --git a/usr/lib/byobu/hostname b/usr/lib/byobu/hostname index 6186f9a0..6ae7b349 100755 --- a/usr/lib/byobu/hostname +++ b/usr/lib/byobu/hostname @@ -25,14 +25,13 @@ __hostname_detail() { __hostname() { local h= + h=$(hostname -s 2>/dev/null || hostname) if metadata_available; then local cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/hostname" # Background a retrieval of our public hostname - wget -q -O- http://169.254.169.254/latest/meta-data/public-hostname "$cache" 2>/dev/null & + timeout 0.2 wget -q -O- http://169.254.169.254/latest/meta-data/public-hostname "$cache" 2>/dev/null & sleep 0.02 [ -s "$cache" ] && read h < "$cache" - else - h=$(hostname -s 2>/dev/null || hostname) fi [ -n "$h" ] || return color bold2; printf "%s" "$h"; color -- diff --git a/usr/lib/byobu/include/shutil b/usr/lib/byobu/include/shutil index 09e1b0d8..4f3dc767 100755 --- a/usr/lib/byobu/include/shutil +++ b/usr/lib/byobu/include/shutil @@ -218,7 +218,7 @@ metadata_available() { # Must seed the cache if [ -e /etc/ec2_version ] || [ -e /usr/sbin/update-grub-legacy-ec2 ]; then # This *looks* like a machine with metadata, so background a potentially slow check - wget -q -O- --timeout=10 --tries=1 http://169.254.169.254 "$cache" 2>/dev/null & + timeout 1 wget -q -O- --tries=1 http://169.254.169.254 "$cache" 2>/dev/null & sleep 0.02 [ -s "$cache" ] && x=1 fi diff --git a/usr/lib/byobu/ip_address b/usr/lib/byobu/ip_address index 7a53d94f..55d2bce7 100755 --- a/usr/lib/byobu/ip_address +++ b/usr/lib/byobu/ip_address @@ -42,7 +42,7 @@ __ip_address() { 1|true|yes) if [ "$IP_EXTERNAL" = "1" ]; then # Background an update - wget -q -O- http://v6.ipv6-test.com/api/myip.php "$cache" 2>/dev/null & + timeout 1 wget -q -O- http://v6.ipv6-test.com/api/myip.php "$cache" 2>/dev/null & sleep 0.02 else # Background an update @@ -61,12 +61,12 @@ __ip_address() { ;; *) if [ "$IP_EXTERNAL" = "1" ]; then - wget -q -O- http://v4.ipv6-test.com/api/myip.php "$cache" 2>/dev/null & + timeout 1 wget -q -O- http://v4.ipv6-test.com/api/myip.php "$cache" 2>/dev/null & sleep 0.02 [ -s "$cache" ] && read ipaddr < "$cache" elif metadata_available; then # We're in EC2, so get our public IP address - wget -q -O- http://169.254.169.254/latest/meta-data/public-ipv4 "$cache" 2>/dev/null & + timeout 0.2 wget -q -O- http://169.254.169.254/latest/meta-data/public-ipv4 "$cache" 2>/dev/null & sleep 0.02 [ -s "$cache" ] && read ipaddr < "$cache" else