Commit 0c065da
committed
fix(devmgr): auto-reconnect stale LAN MQTT and recover startup race
LAN-mode-only printers (no Bambu cloud login) had two related failure
modes that left the user manually re-selecting the printer to make
Studio talk to it again. This commit fixes both -- they share the same
root surface (DeviceManager + TryLoadLastMachine), affect the same
users, and reproduce on the same workflow, so they ship together.
== Stale MQTT socket recovery (DeviceManagerRefresher::on_timer) ==
After idling, macOS App Nap, the local network stack, or the printer
can silently drop the MQTT-over-TLS TCP session. The next
publish_gcode() returns BAMBU_NETWORK_ERR_SEND_MSG_FAILED (-4) and the
user has to manually re-select the printer to trigger the
disconnect+reconnect path in DeviceManager::set_selected_machine.
on_timer's existing keep_alive() / refresh_connection() calls are
gated on is_user_login() and never run for LAN-only users. Add a
parallel branch that fires when all of these hold:
- obj->is_lan_mode_printer() && obj->has_access_right()
- obj->is_avaliable() (bind_state == "free")
- !obj->is_in_printing() (don't clobber print UI mid-print)
- !obj->is_connected() (last MQTT push older than 30s)
When the gate passes, re-select the same machine id. That triggers
the same-id-LAN branch in set_selected_machine which runs
disconnect_printer -> reset -> connect -- the same path the manual
workaround takes. Throttled to one attempt per 10s, bumped only on a
successful set_selected_machine so a transient false return doesn't
delay the next chance to recover.
== Startup-race recovery (TryLoadLastMachine via SSDP) ==
TryLoadLastMachine::InnerLoad fires within milliseconds of app start,
before SSDP has announced the printer's current IP. If the cached
user_access_dev_ip is stale (slicer_uuid rotated since pairing, or
DHCP gave the printer a new IP), bind_detect returns -2 immediately,
erases user_access_dev_ip, and bails. The cloud fallback also fails
because the LAN printer isn't in the list yet. By the time SSDP
populates localMachineList ~1-3s later, no further InnerLoad retry
runs and the printer is discovered-but-not-selected (see upstream
issue #9445).
Add GUI_App::try_load_last_machine_on_alive(dev_id) and call it from
DeviceManager::on_machine_alive whenever an SSDP packet announces a
previously-paired printer. The retry's InnerLoad finds
user_access_dev_ip empty (the failed first attempt erased it) and
falls through to the dev->get_my_machine non-null branch in
GUI_App.cpp, which calls set_selected_machine directly. No second
bind_detect is spawned. The method self-filters on dev_id ==
get_user_last_machine() and no-ops if a machine is already selected,
so per-SSDP-packet invocation is cheap.
== Test plan ==
Stale-MQTT: idle the app >30min on macOS with a LAN-only printer.
Without patch, Send to Printer returns -4; with patch, the next 1Hz
refresher tick auto-reconnects and the send succeeds. Verify the log
line "LAN auto-reconnect: stale MQTT socket detected for dev_id=...".
Startup race: with a stale user_access_dev_ip (rotate slicer_uuid in
BambuStudio.conf, or power-cycle the router so SSDP is delayed),
launch Studio. Without patch the printer is never selected; with
patch the SSDP packet triggers a retry and selection succeeds.
Verify "try_load_last_machine_on_alive: SSDP-triggered retry for ...".
== Limitations ==
- After studio inactivity (>15min), the first user action after
wake may still see one failed send before stale-MQTT auto-
reconnect runs on the next refresher tick. A subsequent send
within 1s succeeds.
- The 10s throttle is a function-static, not per-dev-id, so in
multi-printer households a recent reconnect attempt on printer
A can delay the next attempt on printer B by up to 10s.
- TryLoadLastMachine's destructor joins local_bind_thread; an
SSDP-triggered InnerLoad firing during app shutdown can stall
the join 1-3s waiting for the bind_detect timeout.
Addresses upstream issue #9445.1 parent e8c7dc1 commit 0c065da
3 files changed
Lines changed: 129 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
282 | 309 | | |
283 | 310 | | |
284 | 311 | | |
| |||
909 | 936 | | |
910 | 937 | | |
911 | 938 | | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
912 | 1002 | | |
913 | 1003 | | |
914 | 1004 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2650 | 2650 | | |
2651 | 2651 | | |
2652 | 2652 | | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
| 2659 | + | |
| 2660 | + | |
| 2661 | + | |
| 2662 | + | |
| 2663 | + | |
| 2664 | + | |
| 2665 | + | |
| 2666 | + | |
| 2667 | + | |
| 2668 | + | |
| 2669 | + | |
| 2670 | + | |
| 2671 | + | |
| 2672 | + | |
| 2673 | + | |
| 2674 | + | |
| 2675 | + | |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
2653 | 2679 | | |
2654 | 2680 | | |
2655 | 2681 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
368 | 381 | | |
369 | 382 | | |
370 | 383 | | |
| |||
0 commit comments