Skip to content

Commit

Permalink
Fixed detecting number of NICs in EC2 (#14252)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlimat committed Feb 12, 2022
1 parent 623fdf9 commit 9bd7ce0
Showing 1 changed file with 10 additions and 2 deletions.
Expand Up @@ -23,6 +23,7 @@
import com.sun.management.OperatingSystemMXBean;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -231,8 +232,15 @@ private boolean isPhysicalNic(Path path) {
Files.readAllBytes(path.resolve("speed"));
return true;
} catch (Exception e) {
// wireless nics don't report speed, ignore them.
return false;
// In some cases, VMs in EC2 won't have the speed reported on the NIC and will give a read-error.
// Check the type to make sure it's ethernet (type "1")
try {
String type = new String(Files.readAllBytes(path.resolve("type")), StandardCharsets.UTF_8).trim();
return Integer.parseInt(type) == 1;

This comment has been minimized.

Copy link
@michaeljmarshall

michaeljmarshall Feb 25, 2022

Member

@merlimat - by returning true here, in some cases, don't we also need to update the logic in getNicSpeedPath? We're seeing the new error here #14340 because this class is returning true in a new case.

This comment has been minimized.

Copy link
@michaeljmarshall

michaeljmarshall Feb 25, 2022

Member

Didn't mean to comment on the cherry-pick. Copying to the main PR for this commit.

} catch (IOException ioe) {
// wireless nics don't report speed, ignore them.
return false;
}
}
}
return false;
Expand Down

0 comments on commit 9bd7ce0

Please sign in to comment.