Skip to content

Stop the snapmaker_connection CLI when Orca quits on macOS (#1238) - #1240

Open
alandebortolo wants to merge 1 commit into
Snapmaker:mainfrom
DesignMaster-Solutions:fix/macos-stop-cli-on-exit
Open

alandebortolo wants to merge 1 commit into
Snapmaker:mainfrom
DesignMaster-Solutions:fix/macos-stop-cli-on-exit

Conversation

@alandebortolo

@alandebortolo alandebortolo commented Nov 22, 2026 •

Copy link
Copy Markdown

Fixes #1238 on the Orca side: on macOS, quitting Orca now stops the snapmaker_connection CLI it started, so the next Orca launches a fresh one instead of reusing an orphan.

Why. GUI_App::shutdown() calls stop_gateway_service(), which stops GatewayService (worker, websocket) but leaves the detached CLI running. After the quit it is reparented to launchd (ppid 1). The next Orca's /api/health check returns 200, so no stale-owner takeover happens and the orphan is reused. In the log attached to #1238, that orphan fails every LAN connect in 1-2 ms with EHOSTUNREACH while nc to the same IP and port works from the same Mac, and a freshly started CLI connects first time. That matches macOS Local Network privacy being tied to the responsible (launching) app; the reporter also lists a Wi-Fi change as a possible confound, so I have not proved the cause, only that a fresh CLI works where the orphan does not.

Change (+45 -5, 5 files; 31 of the added lines are the test).

  • GatewayService::stop(bool terminate_cli = false): after the worker joins, calls process_manager->terminate() when asked. Default keeps today's behaviour for every other caller.
  • GUI_App::stop_gateway_service(bool terminate_cli = false) passes it through.
  • GUI_App::shutdown() passes !isRecreate on macOS only. GUI recreation (start_gateway_service(true) after mainframe->shutdown(true)) and Windows/Linux are unchanged.
  • Test: GatewayService stop terminates the CLI only when asked (tests/slic3rutils), using the existing RecordingProcessManager: 0 terminate calls with false, exactly 1 with true, and a second stop() stays a no-op.

Limits, honestly.

  • The gateway tests (GatewayService.cpp, ConnectionProcessManager.cpp, Http.cpp and GatewayService_test.cpp against Boost 1.84) were compiled and run locally on macOS: 17 test cases pass, and the new test fails with the fix removed (details in the first comment). I have not built the full app.
  • terminate() kills only the CLI this Orca spawned (the tracker). A user who already has an orphan from an earlier session still needs one manual kill or reboot after updating; from then on each quit cleans up. Teaching the health check to spot a stale owner (your third option in [2.4.1][macOS] After restarting Orca, the reused snapmaker_control helper fails every LAN connect instantly with "No route to host" (errno 65) until it is killed #1238) would cover that, but it needs a signal from the CLI that it cannot reach the LAN, which I cannot see from Orca's side.
  • If two Orca instances ever share one CLI on macOS, quitting the one that spawned it drops the other's connection until its reconnect loop starts a new CLI (that loop already force-restarts the CLI on failure).
  • I do not own a U1, so I have not reproduced the LAN failure itself.

@alandebortolo

Copy link
Copy Markdown
Author

Compiled and ran the gateway tests for this branch locally on macOS (arm64, Apple clang), building the gateway_tests sources against Boost 1.84 (the version pinned in deps/Boost/Boost.cmake), Catch2 3.16 and nlohmann-json 3.12. Sentry and Slic3r::data_dir() were stubbed; everything else (GatewayService.cpp, GatewayProtocol.cpp, ConnectionProcessManager.cpp, Http.cpp, GatewayService_test.cpp) is the branch code as is.

  • Branch f06a69a, ./gateway_tests '[gateway][service]': All tests passed (151 assertions in 17 test cases).
  • The new test fails when the fix is removed: with the process_manager->terminate() call in stop() replaced by a no-op, GatewayService stop terminates the CLI only when asked fails at line 713 with 0 == 1 (terminate_cli=true section). With the fix restored it passes again.
  • Separate, pre-existing flake on macOS: GatewayWebSocketTransport drains a connected websocket before teardown (line 412, opened_future.wait_for(2s)) fails intermittently. It does the same on main without this PR: 8 failures in 12 runs of the suite built from origin/main, 2 in 6 runs on this branch. This PR does not touch that path.

Still not done here: a full app build and a LAN send to a real U1 after restarting Orca.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants