Fix race between network.service and NIC driver probe (issue #556) #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π€ This PR was written by Claude (operated by Boris), requested by Paul in oc-exchange#18 for mariux64/mxtools#556.
Problem
network.serviceorders itself onlyAfter=sysinit.targetand then runsmxnetctl start+ip addr add β¦ dev ${MX_NETDEV}unconditionally. When the NIC driver is still probing (aftermxgrub --reboot/kexec, userspace starts ~2 s after the kernel while e.g. the ixgbe SFP+/PHY probe needs ~1 s), the device is not yet in/sys/class/net:mxnetctl startcannot rename it and everyipcommand fails β on fluffybuttnet04was missing after kexec. A cold boot only wins this race by accident, because firmware POST gives the driver a multi-second head start.Fix
The wait has to happen before
mxnetctl start, not just before theipcalls:net04only exists oncemxnetctl starthas renamed the kernel device, and it can only do that if the hardware has probed. Waiting for the name alone would therefore spin forever on a first configuration.mxnetctl wait DEVICE(new subcommand): polls every 100 ms until either a device with the target name exists, or hardware whose MAC address is mapped to that name in/etc/local/mxnetshows up (i.e. the NIC has probed but still carries its kernel name). Exits non-zero after--timeoutseconds (default 30) so a genuinely missing device still fails visibly instead of hanging boot.network.service:ExecStartPre=/usr/sbin/mxnetctl wait ${MX_NETDEV}(theEnvironmentFileis already loaded at that point).This is deliberately host-agnostic β one unit change fleet-wide, no per-host drop-ins, and it reuses mxnetctl's existing
/etc/local/mxnetparsing (option A from the analysis in mariux64#556, moved from a shell loop into mxnetctl so the MAC fallback works on hosts that haven't been renamed yet).Testing
perl -cpasses; functional checks on a Debian 13 VM:mxnetctl wait loβ exit 0 instantly (name match)mxnetctl wait --timeout=1 net99β exit 1 after ~1 s withtimeout waiting for network device net99/etc/local/mxnetmapping eth0's MAC tonet99, no device namednet99βmxnetctl wait net99exit 0 instantly (MAC match β the actual race-fix path)Not tested on real MarIuX hardware; a kexec reboot on fluffybutt with this in place would be the real verification.
Remaining smell (out of scope)
The wait covers
${MX_NETDEV}only. Other NICs that probe late still keep their kernel names for that boot, sincemxnetctl startruns once and nothing re-runs it on device add β VLAN/secondary interfaces on fast-booting hosts could hit the same class of race. A udev rule invoking the rename logic per device would fix that structurally (that direction is what PR #1's systemd-networkd generator eventually obsoletes anyway).