Repository navigation
Undo an interrupted ttp start instead of exiting 0 with its changes in place - #185
Merged
Merged
Conversation
…n place SIGINT or SIGTERM during ttp start ran a handler that called do_stop. Before the session lock exists (Tor setup, rules, DNS overlay), do_stop returns at once: the inet ttp table, the overlay and the managed Tor stayed, ttp status said INACTIVE, ttp stop said no session was found, and start exited 0, so a script that trusted it believed the host was protected. After the lock it stopped the session, but still exited 0. The handler now only raises StartInterrupted (a BaseException, so no except Exception in the start path swallows it). Tearing down inside the handler could race an nft or systemctl child still running under the interrupted call; raised, that call unwinds first and kills its child. interruptible_start, around start_command (and so restart), then: - with no session lock: undoes the start as stop --restore-only does, closing connections redirected during the start before the rules go, and exits 1; a retained VPN guard is kept, exit 10, as before; - with a recorded session: stops it and exits 1; a latched or unreadable emergency is retained, exit 8, as before. Both signals are ignored while the undo runs. The restore-only teardown moves from stop_command to lifecycle.restore_without_session so both paths share it. docs/web/explanation/startup.md states the startup contract phase by phase (L01 of the leak-testing plan): what each phase changes, where the first barrier falls, and what a failure or an interruption leaves. Tests interrupt start inside Tor setup, the rules load and the DNS overlay, and after the session is recorded; all but the latched case fail against the old handler. A conftest fixture restores SIGINT and SIGTERM after each test, since start installs its handler in the test process. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
…tart Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com> # Conflicts: # CHANGELOG.md # docs/web/release-notes/changelog.md
…tart Signed-off-by: onyks-os <129986281+onyks-os@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.
This PR fixes a bug found while inventorying L01 of the leak-testing plan (slice 2): the startup and rollback contract.
The defect
The SIGINT/SIGTERM handler registered by
ttp startcalleddo_stop(). Before the session lock exists, that function returns immediately. Interruptingttp startduring Tor setup, the rules load or the DNS overlay therefore:inet ttptable, the DNS overlay and the managed Tor in place;ttp statusto reportINACTIVEandttp stopto report "No active session found";A script that trusted that exit code believed the host was protected. When the interruption came after the session lock was written, the session was stopped, but start still exited 0.
The fix
StartInterrupted, aBaseException.nftorsystemctlchild that is still running.subprocess.runkills and reaps its child.interruptible_startwrapsstart_command, so it also coversrestart.stop --restore-onlyundoes it. Connections redirected during the start are closed before the rules go. Exit 1.lifecycle.restore_without_session, so both paths share it.Documentation
docs/web/explanation/startup.mdstates the startup contract phase by phase: what each phase changes, where the first barrier falls, and what a failure or an interruption leaves behind. The page is added to the nav and linked from the plan's L01 note. The external measurement of the first barrier is still pending; it waits for the continuous capture of slice 3.Tests
🤖 Generated with Claude Code