Skip to content

Commit

Permalink
fix: do not log warnings about disabled net ifaces
Browse files Browse the repository at this point in the history
  • Loading branch information
zharkovstas committed Apr 8, 2024
1 parent 641dce2 commit d37fa4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.21 (08-04-2024):

Do not log warnings about disabled network interfaces on newer Linux kernels.

## 0.3.20 (22-09-2023):

Return back changes from 0.3.18 using RuntimeDetector to fix "Overlapped I/O operation is in progress" exception for framework 4.7.2/4.8.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ NetworkUsage CreateNetworkUsage(string interfaceName, long receivedBytes, long s
}

// NOTE: See https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net for details.
// NOTE: This value equals -1 if interface is disabled, so we will filter this values out later.
// NOTE: This value equals -1 if interface is disabled on older kernels, so we will filter this values out later.
foreach (var networkUsage in networkInterfacesUsage.Values)
{
if (TryReadSpeed(networkUsage.InterfaceName, out var result) && int.TryParse(result, out var speed))
Expand Down Expand Up @@ -235,6 +235,12 @@ private static bool TryReadSpeed(string interfaceName, out string result)
result = File.ReadAllText(path);
return true;
}
// NOTE: Disabled interfaces give this error on newer kernels.
catch (IOException ioError) when (ioError.Message.StartsWith("Invalid argument"))
{
result = null;
return false;
}
catch (Exception error)
{
// NOTE: We expect teaming interface to not be able to read speed directly.
Expand Down

0 comments on commit d37fa4e

Please sign in to comment.