Skip to content

Commit

Permalink
fix: Sort links before fetching sysfs link infos
Browse files Browse the repository at this point in the history
When fetching link info from sysfs, `os.listdir(path)` returns entries
in arbitrary order, which can cause intermittent errors when a VLAN
device appears before its parent. This leads to a "no such interface
exists" error on repeated configuration application. Sorting the list
before processing ensures deterministic behavior, making it consistent
and more predictable given the VLAN's device name.

Signed-off-by: Wen Liang <[email protected]>
  • Loading branch information
liangwen12year authored and Wen Liang committed Feb 11, 2025
1 parent 1b57520 commit 46c3cea
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion library/network_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _link_read_permaddress(ifname):
@staticmethod
def _link_infos_fetch():
links = {}
for ifname in os.listdir("/sys/class/net/"):
for ifname in sorted(os.listdir("/sys/class/net/")):
if not os.path.islink("/sys/class/net/" + ifname):
# /sys/class/net may contain certain entries
# that are not interface names, like
Expand Down

0 comments on commit 46c3cea

Please sign in to comment.