Skip to content

network: re-track devices after NetworkManager restarts - #4112

Merged
bbedward merged 2 commits into
duxlabs-dev:masterfrom
yebei199:fix/network-nm-restart-resync
Nov 5, 2026
Merged

bbedward merged 2 commits into
duxlabs-dev:masterfrom
yebei199:fix/network-nm-restart-resync

Conversation

@yebei199

@yebei199 yebei199 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

After NetworkManager restarts (for example during a system configuration switch, or by running systemctl restart NetworkManager directly), switching to a wired connection does not update the DMS icon. It only recovers after restarting DMS.

I hit this on my own machine and have been running the fix locally since. When I first started using DMS, the maintainers patiently helped me with several issues (#217, #243, #286, #493, #523), so I wanted to contribute this back in case it's useful. Happy to adjust anything.

Fix: once NetworkManager is back online, DMS syncs its devices again.

The code was written with AI assistance. I have read it and verified it by applying it as a patch on my own NixOS.

D-Bus signals captured during systemctl restart NetworkManager:

20.694  NameOwnerChanged  org.freedesktop.NetworkManager  :1.10987 -> ""
20.832  DeviceAdded       /org/freedesktop/NetworkManager/Devices/16   (ethernet)
20.835  DeviceAdded       /org/freedesktop/NetworkManager/Devices/23   (wifi)
21.011  NameOwnerChanged  org.freedesktop.NetworkManager  "" -> :1.11154

Tests: make fmt clean, make test passes, go mod tidy clean.
TestNetworkManagerBackend_EthernetDeviceSurvivesNetworkManagerRestart fails without the fix.
make vet fails on mock_NetworkManager.go:2106 (MarshalJSON), same on master.

Type of change

  • Bug fix (non-breaking change that fixes an issue)

When NetworkManager restarts it emits DeviceAdded for every device before it
owns org.freedesktop.NetworkManager again (about 180 ms earlier on the machine
this was captured on). handleDeviceAdded looks the device up through the
well-known name, the call fails with ServiceUnknown, and the device is dropped.
Wi-Fi recovers through refreshWiFiDevices, but an ethernet device stays missing
until the shell restarts, so the bar shows the Wi-Fi icon while traffic goes
over the wire.

Watch NameOwnerChanged for org.freedesktop.NetworkManager and, once the name
has a new owner, replay handleDeviceAdded for devices that are not tracked.
The device constructors become backend fields so a test can reproduce the
failed lookup.
@github-actions github-actions Bot added core Go daemon and CLI under core/ fix labels Nov 4, 2026
@bbedward

bbedward commented Nov 4, 2026

Copy link
Copy Markdown
Member

/claude review

@claude

claude Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Claude review

The fix works for devices that were never tracked, but devices from the dead NetworkManager instance stay tracked, so wired actions can hit a dead object path.

  • resyncDevices never drops entries from the old NetworkManager, so b.ethernetDevice/b.cellularDevice stay on a dead path after a path change, core/internal/server/network/backend_networkmanager_signals.go:664
    Checked: NameOwnerChanged match add/remove and filtering, effect on other NameOwnerChanged consumers on the shared bus, device tracking and selection, the mockery config and generated mock, tests. Model: claude-opus-5-5.

A NetworkManager that dies emits no DeviceRemoved. If the restarted daemon
gives an interface a new object path, the device map gets the new entry, but
ethernetDevice and cellularDevice keep pointing at the dead path, so wired and
cellular actions call a dead object and the old PropertiesChanged match leaks.

resyncDevices now diffs the tracked paths against GetDevices(): paths that
are gone go through handleDeviceRemoved, which reselects the device and
removes the match; new paths go through handleDeviceAdded as before.
@bbedward

bbedward commented Nov 5, 2026

Copy link
Copy Markdown
Member

/claude review

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Claude review

No issues found. The earlier finding is fixed: resyncDevices now drops paths from the dead NetworkManager through handleDeviceRemoved before it adds the new ones.
Checked: the NameOwnerChanged match add/remove and name filtering, other NameOwnerChanged consumers on the shared system bus (loginctl filters by name), the order of removal and re-add, reselection of the ethernet/wifi/cellular device and cleanup of the PropertiesChanged match, locking in trackedDevicePaths, the injected device constructors, the mockery config and generated MockDeviceWired, tests. Model: claude-opus-5-5.

@bbedward
bbedward merged commit 784afec into duxlabs-dev:master Nov 5, 2026
4 checks passed
dux-ci Bot pushed a commit that referenced this pull request Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Go daemon and CLI under core/ fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants