Skip to content

Network: resolve the WiFi device on use instead of caching its D-Bus path - #3

Open
xtrack33 wants to merge 1 commit into
masterfrom
fix/wifi-device-resolved-on-use
Open

xtrack33 wants to merge 1 commit into
masterfrom
fix/wifi-device-resolved-on-use

Conversation

@xtrack33

@xtrack33 xtrack33 commented Nov 7, 2026

Copy link
Copy Markdown

The failure

On a bench pad the network panel listed nothing and announced no WiFi adapter, while wlan0 was associated and routing fine. Its log:

sdbus.dbus_exceptions.DbusUnknownMethodError:
  Object does not exist at path "/org/freedesktop/NetworkManager/Devices/5"
  → sdbus_nm.py get_networks()     self.wlan_device.access_points
  → sdbus_nm.py get_ip_address()   self.wlan_device.interface
  → network.py  load_networks()    → empty list

NetworkManager had wlan0 on Devices/4; the panel was still addressing Devices/5.

SdbusNm resolved the device once in __init__ and kept that proxy, bound to one object path. NetworkManager destroys the device object and builds a new one at a new path whenever the adapter is re-probed — a USB dongle replugged, or its driver reloaded by sonar's WiFi recovery. Nothing revalidated the proxy, so the panel stayed empty for the rest of the session. No systemd ordering can cover this: the replacement happens mid-session.

The other half: starting before the USB dongle is enumerated left wlan_device at None and __init__ dereferenced it.

The change

  • wlan_device is resolved on use, never kept. An explicit choice pins the interface name, which survives a re-probe, instead of the proxy.
  • wifi becomes a property for the same reason: it was a snapshot taken once.
  • __init__ tolerates no adapter, and a panel built without one asks for a rebuild, so a late dongle fills it on the next opening rather than keeping a layout whose network list is not in the widget tree.
  • That rebuild is registered under this panel's own name. A panel reaches _cur_panels only once built, so during __init__ the last entry is still the panel we came from and the request landed on the wrong panel.

Measured on a pad

One long-lived process across a real USB rebind of the dongle, which is exactly what sonar's recovery performs:

before        wlan0 = /org/freedesktop/NetworkManager/Devices/4
after         wlan0 = /org/freedesktop/NetworkManager/Devices/5
cached proxy  FAILED DbusUnknownMethodError (path Devices/4)
resolved      wifi=True iface=wlan0 ip=192.168.100.103 networks=5

Same process, dongle taken away and brought back:

no adapter    old __init__  FAILED AttributeError: 'NoneType' object has no attribute 'state'
no adapter    new           wifi=False networks=0, no exception
adapter back  new           wifi=True iface=wlan0 ip=192.168.100.103 networks=6

A restart of NetworkManager alone does not reproduce it: the device objects come back at the same paths. The index only moves when a device is added while NetworkManager is running, which is what a dongle re-probe does.

NetworkManager destroys its device object and builds a new one at a NEW
object path whenever the adapter is re-probed: a USB dongle replugged, or
its driver reloaded by sonar's WiFi recovery. SdbusNm resolved the device
once in __init__ and kept that proxy, so after any of those, every property
access raised

  DbusUnknownMethodError: Object does not exist at path
    "/org/freedesktop/NetworkManager/Devices/4"

out of get_networks() and get_ip_address(), and the panel listed no network
at all until KlipperScreen was restarted. Measured on a pad: the panel was
still talking to Devices/5 while wlan0 had become Devices/4.

Resolve the device on use instead. An explicit choice pins the interface
NAME, which survives a re-probe, not the proxy. `wifi` becomes a property
for the same reason: it was a snapshot taken once, before a late dongle
could exist.

__init__ no longer dereferences a device that is not there: starting before
the USB dongle is enumerated left wlan_device None and crashed on
None.state. A panel built without an adapter now asks for a rebuild, so a
dongle showing up later fills it on the next opening instead of keeping a
layout whose network list is not even in the widget tree. That rebuild is
registered under this panel's own name: a panel reaches _cur_panels only
once built, so during __init__ its last entry is still the panel we came
from, and the request landed on the wrong one.

Verified on a pad, in one long-lived process across a real USB rebind of
the dongle, which is what sonar's recovery performs:

  before        wlan0 = /org/freedesktop/NetworkManager/Devices/4
  after         wlan0 = /org/freedesktop/NetworkManager/Devices/5
  cached proxy  FAILED DbusUnknownMethodError (path Devices/4)
  resolved      wifi=True iface=wlan0 ip=192.168.100.103 networks=5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant