fix(http): lock HttpServer start/restart via start_locked (Snapmaker #870 residual) - #52
Merged
Merged
Conversation
…napmaker#870 residual) Extract start_locked() so start()/restart() hold m_server_mtx across destroy+recreate, then start_health_check() only after the lock is released. Make start_http_server atomic (io-thread write vs unlocked readers). Capture the SSWCP mqtt-connect failure callback as weak_ptr so it cannot pin MqttClient forever. MQTT.cpp/.hpp are unchanged; core markers from Edge #22/#28 already satisfy Snapmaker Snapmaker#870. Co-authored-by: aceRage <aceRage@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Surgical extract of the remaining Snapmaker/OrcaSlicer #870 lifetime/race work onto EdgeSlicer
main. This does not re-land the MQTT stack already present from Snapmaker Snapmaker#847/Snapmaker#855 via Edge #22 / #28.HttpServer::start()still created the IO server without holdingm_server_mtx, andrestart()calledstart()(includingstart_health_check()) while holding that lock. That racedis_healthy()on the health-check thread (UAF / double restart) and could deadlock a join of a retired health-check thread blocked inis_healthy().Residual vs Snapmaker Snapmaker#870 (
6faa813a3c)main(pre this PR)MqttClient::create()+self_weak_ptrMQTT.cpp/.hppuntouchedtearing_down_+cb_mtx_/topics_mtx_Moonraker_Mqtt::m_client_mtx+get_mqtt_client(_tls)snapshotsm_cbs_mtxSSWCP_MachineConnect_Instance::release_pin_client+ pinCallAfterm_server_mtxaroundstop()/restart()/is_healthy()HttpServer::start_locked()start()/restart()hold lock across destroy+recreate; health check after unlockstart()unlocked create;restart()calledstart()under the lock)start_http_serveratomic (io-thread write vs unlocked readers)start_locked)sw_mqtt_connectfailure callback captures engine asweak_ptrDisconnect; no SnapmakerSNAP_LOG_BATCH/ session-id)Files
src/slic3r/GUI/HttpServer.hpp— declarestart_locked();std::atomic<bool> start_http_serversrc/slic3r/GUI/HttpServer.cpp— extract body; lock instart()/restart();start_health_check()after unlocksrc/slic3r/GUI/SSWCP.cpp— weak_ptr engine capture insw_mqtt_connectonlyNot touched: Ultra HttpServer login handlers (
ResponseLoginFailed/BBL_LOGIN_LOCALHOST_URL), SSWCP Ultra unload/archive customs,RemoteSnapmaker.cpp,MQTT.cpp/.hpp,MoonRaker.cpp/.hpp.Intentionally not ported (re-diff, not weak_ptr/
CallAfterresiduals)time_sync_manager_snapshot()/m_time_sync_manager_mtx— mutex snapshot of an already-presentweak_ptr<TimeSyncManager>capture, not a missing CallAfter/weak_ptr guard. Edge still copiestime_sync_manager_without that mutex.disconnect(): Fix MQTT disconnect crash: lifetime & race fixes in MQTT/MoonRaker/HttpServer Snapmaker/OrcaSlicer#870 clears the message callback before resettingtime_sync_manager_; Edge still resets first thenSetMessageCallback(nullptr). Left as-is to avoid a MoonRaker restack.RemoteSnapmaker.cppstill capturesenginebyshared_ptrinSetConnectionFailureCallback— Edge-only Ultra path, not in Fix MQTT disconnect crash: lifetime & race fixes in MQTT/MoonRaker/HttpServer Snapmaker/OrcaSlicer#870's file list.Screenshots/Recordings/Graphs
N/A — concurrency / lifetime fix. No UI change.
Tests
start_locked+ SSWCP engineweak_ptrapplied.MQTT.cpp/.hpphave zero diff.start_locked()underm_server_mtxwithstart_health_check()after unlock, sois_healthy()cannot observe the torn-down gap.Still owed on real hardware (not run in this environment):
is_healthyUAF / double restart