Skip to content

refactor(vpn-monitor): kill/restart instead of RPC pause/resume#60

Merged
smartwatermelon merged 2 commits intomainfrom
claude/vpn-monitor-kill-restart-1770937771
Feb 13, 2026
Merged

refactor(vpn-monitor): kill/restart instead of RPC pause/resume#60
smartwatermelon merged 2 commits intomainfrom
claude/vpn-monitor-kill-restart-1770937771

Conversation

@smartwatermelon
Copy link
Owner

Summary

  • Replace fragile RPC-based pause/resume with kill-and-restart on VPN state changes
  • VPN down: kill Transmission process, verify dead, set bind to 127.0.0.1
  • VPN restored: set bind to VPN IP, relaunch Transmission, verify running
  • Net result: -75 lines of complexity removed

Why this is better

A dead process has zero network activity — no DHT, PEX, or tracker announces can leak. The previous RPC approach left Transmission running (potential leaks) and required bounded-retry logic with give-up notifications for the resume path.

Transmission persists torrent state in its resume files, so previously-active torrents resume on relaunch and paused ones stay paused. No external state tracking needed.

Removed

  • pause_all_torrents() / resume_all_torrents() RPC functions
  • get_session_id() / rpc_call() RPC infrastructure
  • TORRENTS_PAUSED_BY_US / RESUME_RETRY_COUNT / MAX_RESUME_RETRIES state tracking
  • Bounded-retry logic with give-up notification in main loop

Test plan

  • Deploy updated monitor to server
  • Verify VPN down: Transmission process is killed within 5s
  • Verify VPN restore: Transmission relaunches with correct bind-address
  • Verify torrent state preserved across kill/relaunch cycle

🤖 Generated with Claude Code

…/resume

Replace the fragile RPC-based pause/resume approach with kill-and-restart:

VPN down:
  1. Kill Transmission (graceful quit, then force-kill if needed)
  2. Verify process is dead
  3. Set bind-address to 127.0.0.1

VPN restored:
  1. Set bind-address to VPN IP
  2. Relaunch Transmission
  3. Verify process is running

This is more reliable because:
- A dead process has zero network activity (no DHT/PEX/tracker leaks)
- Transmission persists torrent state in resume files — active torrents
  resume on relaunch, paused ones stay paused
- No RPC dependency for the critical "stop all traffic" path
- Eliminates the entire bounded-retry/give-up complexity for resume

Removes: pause_all_torrents, resume_all_torrents, RPC session/call
functions, TORRENTS_PAUSED_BY_US state, RESUME_RETRY_COUNT logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Transmission only reads BindAddressIPv4 at launch. If the monitor starts
while Transmission is already running (e.g., after reboot with a new VPN
IP), defaults write alone doesn't take effect. Always kill and relaunch
on startup to guarantee the correct bind-address is applied.

Found by: Seer Code Review (PR #60)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@smartwatermelon
Copy link
Owner Author

Fixed: Seer correctly identified that the startup path skipped restarting Transmission when it was already running. Now always kill/relaunch on startup to guarantee the bind-address is applied (Transmission only reads BindAddressIPv4 at launch).

@smartwatermelon smartwatermelon merged commit 452a4c5 into main Feb 13, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant