_get_network_card does not retry on empty IMDS responses, causing route metric and table ID collisions on multi-card instances#153
Open
joeysk2012 wants to merge 1 commit into
Conversation
c14ab0a to
5aaa87f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
_get_network_cardinlib/lib.shqueries IMDS for an interface'snetwork-cardvalue exactly once and echoes whatever comes back, including an empty string._get_device_numberalready handles the same propagation race with a 60-attempt retry loop;_get_network_carddoes not.When a hot-plugged ENI's
network-cardvalue has not yet propagated to IMDS, the empty result flows downstream into:sh
local -i network_card="$3"
local -i metric=$((metric_base + 100network_card + device_number))
local -i tableid=$((rule_base + 100network_card + device_number))
Bash coerces the empty string to
0. Two interfaces on different network cards can therefore both be configured withnetwork_card=0, producing duplicate route metrics and routing-table IDs. The same collision affectscreate_rules, which usesdevice_number + rule_base + 100*network_cardfor its policy-rule priority and table.Impact
The race is rare on small instances but reproducible on instance types that expose multiple network cards and attach many ENIs. We've observed it with 60 ENIs. Symptoms include non-deterministic route ordering, policy-rule conflicts, and traffic egressing the wrong interface.
Reproduction (sketch)
networkctl statusandip rule showfor interfaces that share the same metric / table ID, orjournalctl -u 'policy-routes@*'for racing setup runs.Affected code
lib/lib.sh,_get_network_card(around line 535).Proposed fix
Mirror
_get_device_number's retry structure: up to 60 attempts with a 0.1s sleep between tries, single curl per iteration. Accept an empty result after exhaustion to preserve the documented behavior on instance types that legitimately don't exposenetwork-card.sh
getnetwork_card() {
local iface ether network_card
iface="$1"
ether="$2"
if isprimary_interface "$ether"; then
echo 0 ; return 0
fi
local -i maxtries=60 ntries=0
for (( ntries = 0; ntries < maxtries; ntries++ )); do
network_card=$(get_iface_imds "$ether" network-card 1)
if [ -n "$network_card" ]; then
echo "$network_card"
return 0
fi
sleep 0.1
done
echo ""
return 0
}