Skip to content

fix: close SSH tunnels on window close and app termination#217

Merged
datlechin merged 1 commit intomainfrom
fix/ssh-tunnel-cleanup
Mar 9, 2026
Merged

fix: close SSH tunnels on window close and app termination#217
datlechin merged 1 commit intomainfrom
fix/ssh-tunnel-cleanup

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

Summary

Closes #214 — SSH tunnel processes (ssh -N -L) were not terminated when closing a connection window or quitting the app.

Four root causes fixed:

  • Unreliable disconnect trigger: The only path to disconnectSession() was SwiftUI's onDisappear, which can miss window closes. Now WindowLifecycleMonitor posts .lastWindowDidClose via NSWindow.willCloseNotification (always fires), and DatabaseManager observes it as a deterministic disconnect path.
  • No cleanup on app termination: applicationWillTerminate now calls SSHTunnelManager.terminateAllProcessesSync() to kill all SSH processes before exit.
  • waitForProcessExit could hang forever: If the SSH process exited between terminate() and setting terminationHandler, the continuation never resumed. Now guards isRunning, races termination handler vs timeout via TaskGroup, and SIGKILLs as fallback.
  • closeAllTunnels() didn't wait: Now waits for all processes concurrently via TaskGroup.

Test plan

  • Connect to a database via SSH tunnel
  • Run lsof -i | grep ssh — confirm tunnel process exists
  • Close the connection window
  • Run lsof -i | grep ssh — confirm tunnel process is gone
  • Test with multiple windows for same connection (only last close should disconnect)
  • Test app quit with active SSH tunnel — confirm process is terminated

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@datlechin datlechin force-pushed the fix/ssh-tunnel-cleanup branch from c1ebc9d to ba9a6c2 Compare March 9, 2026 03:54
@datlechin datlechin merged commit 60f848c into main Mar 9, 2026
2 checks passed
@datlechin datlechin deleted the fix/ssh-tunnel-cleanup branch March 9, 2026 03:55
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.

Bug: ssh tunnel not closed after closing window

1 participant