Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed detecting number of NICs in EC2 (#14252)
- Loading branch information
Showing
1 changed file
with
10 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
michaeljmarshall
Member
|
||
} catch (IOException ioe) { | ||
// wireless nics don't report speed, ignore them. | ||
return false; | ||
} | ||
} | ||
} | ||
return false; | ||
|
@merlimat - by returning
true
here, in some cases, don't we also need to update the logic ingetNicSpeedPath
? We're seeing the new error here #14340 because this class is returningtrue
in a new case.