Fix stale LAN printer info before local print#11088
Conversation
Timeout logic is wrongnetwork and stuff is not my jam but check src/slic3r/GUI/DeviceManager.cpp in is_info_ready line 2382 What can go wrong if system_clock is used for timeout logic?
std::chrono::system_clock::time_point curr_time = std::chrono::system_clock::now();
auto push_age = std::chrono::duration_cast<std::chrono::milliseconds>(curr_time - last_push_time);The code uses std::chrono::system_clock to measure elapsed time. system_clock is not monotonic and can jump backwards or forwards due to NTP adjustments or user changes, leading to negative ages or premature timeouts. Here is my take for this:Note: make sure that last_push_time is also changed to std::chrono::steady_clock::time_point std::chrono::steady_clock::time_point curr_time = std::chrono::steady_clock::now();
auto push_age = std::chrono::duration_cast<std::chrono::milliseconds>(curr_time - last_push_time); |
| auto diff = std::chrono::duration_cast<std::chrono::microseconds>(last_push_time - curr_time); | ||
| if (m_full_msg_count > 0 && m_push_count > 0 && diff.count() < PUSHINFO_TIMEOUT) { | ||
| auto push_age = std::chrono::duration_cast<std::chrono::milliseconds>(curr_time - last_push_time); | ||
| if (m_full_msg_count > 0 && m_push_count > 0 && push_age.count() >= 0 && push_age.count() < PUSHINFO_TIMEOUT) { |
There was a problem hiding this comment.
The check push_age.count() >= 0 is good for handling system clock adjustments, but ensure PUSHINFO_TIMEOUT is correctly scaled now that the unit changed from microseconds to milliseconds.
There was a problem hiding this comment.
PUSHINFO_TIMEOUT is already defined in milliseconds (15000.f in DeviceManager.hpp), so no additional scaling is needed here. The previous code was actually mixing microseconds with a millisecond timeout, and also computed last_push_time - now, which made the stale check effectively always pass for normal past timestamps. This change intentionally aligns the duration unit with the timeout constant.
I agree steady_clock would be a cleaner choice for elapsed timeout logic; that can be a follow-up, but it is separate from the unit conversion in this patch.
Summary
Root Cause
In LAN/developer mode, stale printer push data could be treated as ready, so the print dialog showed cached device information while the local MQTT publish path was no longer valid. Printing then failed with local print publish error (-4030). After correcting the readiness check, the dialog exposed the real issue: it waited until timeout without re-triggering the same LAN reconnect flow users performed manually by reselecting the printer.
Verification
BambuStudio_app_guisuccessfully with VS 2022:cmake --build build-verify --config Release --target BambuStudio_app_gui -- /m /nr:false /v:minimal