{"record":{"id":"858a68c4adac5a6f","repo":"kubernetes/kops","slug":"reading-primary-mac-address-from-ec2-metadata-w","errorCode":null,"errorMessage":"reading primary MAC address from ec2 metadata: %w","messagePattern":"reading primary MAC address from ec2 metadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nodeup/pkg/model/networking/eni_networking.go","lineNumber":201,"sourceCode":"}\n\n// primaryInterfaceName gives the name of the primary network interface. It gets the MAC address\n// of the primary ENI (device-number 0) from the IMDS item \"mac\". Then it compares this MAC\n// address with the physical network interfaces in sysfs.\nfunc primaryInterfaceName(ctx context.Context) (string, error) {\n\tconfig, err := awsconfig.LoadDefaultConfig(ctx)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"loading AWS config: %w\", err)\n\t}\n\tmetadata := imds.NewFromConfig(config)\n\tresp, err := metadata.GetMetadata(ctx, &imds.GetMetadataInput{Path: \"mac\"})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"getting primary MAC address from ec2 metadata: %w\", err)\n\t}\n\tdefer resp.Content.Close()\n\tmac, err := io.ReadAll(resp.Content)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"reading primary MAC address from ec2 metadata: %w\", err)\n\t}\n\n\treturn findPhysicalInterfaceByMAC(\"/sys/class/net\", strings.TrimSpace(string(mac)))\n}\n\n// findPhysicalInterfaceByMAC gives the name of the physical network interface that has the\n// specified MAC address. The function ignores the virtual interfaces (veths, bridges, VLANs),\n// because a virtual interface can have the same MAC address as a physical interface. The\n// function gives an error if it does not find exactly one physical interface with this MAC\n// address.\nfunc findPhysicalInterfaceByMAC(sysClassNet string, mac string) (string, error) {\n\tentries, err := os.ReadDir(sysClassNet)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"reading %s: %w\", sysClassNet, err)\n\t}\n\n\tvar matches []string\n\tfor _, entry := range entries {","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/nodeup/pkg/model/networking/eni_networking.go#L183-L219","documentation":"Thrown when io.ReadAll(resp.Content) fails after a successful GetMetadata('mac') — i.e. the IMDS response body could not be fully read (connection dropped mid-read, truncated response, IO error on the HTTP body stream).","triggerScenarios":"The IMDS HTTP response body stream errors during io.ReadAll: connection reset by the metadata service mid-response, read timeout on the body, or an interrupted local link-local connection.","commonSituations":"Flaky link-local networking on the instance, IMDS connection reset under high concurrency (many parallel IMDS clients), intermittent network driver issues right after boot.","solutions":["Re-run nodeup — a one-off IMDS read interruption is usually transient","Check for IMDS rate limiting/many concurrent clients and add backoff","Verify the ENA driver and link-local connectivity health (dmesg for ena errors)","If persistent, inspect for network interception of 169.254.169.254 traffic"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"mac, err := io.ReadAll(resp.Content)\nif err != nil {\n    return \"\", fmt.Errorf(\"reading primary MAC address from ec2 metadata: %w\", err) // callers should retry nodeup\n}","preventionTips":["Retry IMDS reads with backoff on transient IO errors","Limit concurrent IMDS clients on the node","Monitor for link-local connection resets in node logs","Re-run nodeup after transient boot-time network storms"],"tags":["aws","imds","io","network"],"backgroundTag":"imds-read-interrupted","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}