Repository navigation
Description
Bug Description
Follow-up to #16 (closed via #23). Reported by sLimbutin in Discord: Bridge still fails to recover when waking the PC from hibernation. #23 only relaunches the process when the eframe/Glow tray loop exits — if the process survives hibernate, nothing recovers the HID state.
Repro
- Open Bridge, connect a mouse
- Hibernate the PC (~10 min), wake it
- Bridge is either gone or (worse) still running but the device no longer responds; webapp/Desktop show stale controls
Root cause (code read, not yet runtime-verified)
Two gaps, both in current main:
-
No power/resume handling at all.
grep -rni suspend/resume/hibernate/PBT_ /tmp/bridge/srcfinds nothing except UI wakers andthread::sleep. Nothing listens forWM_POWERBROADCAST / PBT_APMRESUME(Windows) or suspend/resume hooks (Linux), so after resume the runtime keeps whatever HID state it had going into hibernate. -
Stale-handle reuse in
src/hid.rsHidSession::open().open()early-returnsOkwhen the key is already inopen_deviceswithout validating the handle. After hibernate, USB re-enumerates (new paths) and pre-hibernateHidDevicehandles are dead, but Bridge keeps reporting open-success and every subsequent read/write fails.reconcile_inventory()only runs onlist, so a connected webapp that never re-lists keeps using dead handles forever. The per-sessionHidApiinstance is also created once (HidSession::new) and only refreshed onlist.
Proposed fix
- Short term: on any HID I/O failure, do one
refresh_devices() + reopen same pathretry before erroring; evict the deadopen_devicesentry so the nextopenactually reopens instead of returning Ok on a dead handle. Return a typed device-gone error so the webapp re-opens. - Proper fix: handle resume explicitly — Windows hidden window for
PBT_APMSUSPEND / PBT_APMRESUME, Linux suspend/resume hook — posting aBridgeCommand::SystemResumedthat refreshes enumeration, drops all open handles/readers, and pushes a fresh snapshot so the panel re-lists. - Optional: watchdog for the alive-but-dead tray case (process up, Glow loop stalled) since Relaunch Bridge after the tray panel dies on hibernate #23 only covers loop exit.
Needed to confirm
- Bridge log around the hibernate/wake window (does the process exit + relaunch, or stay up with HID errors?)
- OS + Bridge version, wired vs 2.4 GHz
- Whether re-listing / re-opening the device in the webapp (without restarting Bridge) recovers it — distinguishes stale-handle vs dead-process
Activity
Recover HID devices after hibernate/resume (fixes OpenMouse-Project#27)