Feature: Graceful shutdown#3
Merged
Merged
Conversation
… window. Update ROADMAP.md.
…. Notify user in web UI when process dies on the back end. Adapt to multiple process termination scenarios. Update documentation.
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.
Summary
Comprehensive rewrite of the shutdown path to ensure the belt always stops and BLE disconnects cleanly, plus a web UI notification so users see "Server is shutting down" instead of their browser silently going dead.
Problem
run.pysent SIGINT to both the wrapper and Waitress subprocess (same process group), causing race conditions: connection reset errors, belt potentially left running, no UI notificationRuntimeError: Event loop stopped before Future completed_deferred_exitonly waited 1s, not enough time for the browser's/statspoll to arrive and receive the shutdown signalChanges
app.py_server_stoppingflag exposed via/statsendpoint so all session templates can detect shutdown/statswithstopping: trueloop.run_until_complete(_connect_to_pad())in try/except forRuntimeErrorto catch the race when shutdown interrupts BLE scanningrun.pypreexec_fn=os.setsid()tosubprocess.Popen()so Waitress runs in its own process group. Ctrl+C only hitsrun.py/shutdownbefore terminating, with 15s timeout (BLE cleanup can take a few seconds)Templates
active_session.html,paused_session.html,start_session.htmlall checkdata.stopping === truein their/statspoll callback and display "Server is shutting down. You may close this window."Documentation
CHANGELOG.md: added shutdown notification and BLE scanning race condition fixesROADMAP.md: updated section 1.2 with accurate implementation details (os._exit, UI notification, process isolation)README.md: updated graceful shutdown descriptionShutdown Flow (Ctrl+C)
run.pycatches KeyboardInterrupthttp://127.0.0.1:5001/shutdownon still-alive Waitress server_server_stopping = True, does BLE cleanup, returns response/statspoll (within ~1.5s) receivesstopping: trueand displays shutdown messageos._exit(0)run.pywaits 6s then callsterminate()as safety net