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 69de8d7 commit d7ecdfa
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;
} catch (IOException ioe) {
// wireless nics don't report speed, ignore them.
return false;
}
}
}
return false;
Expand Down

0 comments on commit d7ecdfa

Please sign in to comment.