fix: SSH-tunneled connections failing to reconnect after idle/sleep#739
Merged
fix: SSH-tunneled connections failing to reconnect after idle/sleep#739
Conversation
…736) The health monitor's reconnectDriver now rebuilds the SSH tunnel instead of reusing a stale localhost port. Added OS-level TCP keepalive on SSH sockets, wake-from-sleep tunnel validation, App Nap prevention, nil password guard with descriptive errors, reentrancy guard for concurrent recovery, and increased retry budget from 5 to 10 attempts.
Log libssh2 detail at error level but throw .authenticationFailed instead of .tunnelCreationFailed to avoid misleading "SSH tunnel creation failed" prefix in user-facing messages. Replace dead ?? "" fallbacks with guard let after nil password check.
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
Fixes #736 — SSH-tunneled connections through AWS EC2 show password/authentication errors after being idle for days.
Root causes identified and fixed:
reconnectDriverreused a staleeffectiveConnectionpointing at127.0.0.1:<dead_port>. Now callsbuildEffectiveConnectionfor SSH sessions to create a fresh tunnel.SO_KEEPALIVE, so AWS NAT gateway idle timeouts (350s) silently dropped connections. AddedSO_KEEPALIVE+TCP_KEEPALIVE(60s idle).NSWorkspace.didWakeNotificationobserver to proactively validate SSH tunnels on wake instead of waiting for the 30s health monitor ping.ProcessInfo.beginActivity(.userInitiatedAllowingIdleSystemSleep)while tunnels are active.libssh2_session_last_errordetail inPasswordAuthenticatorandKeyboardInteractiveAuthenticator.handleSSHTunnelDiedconcurrently. AddedrecoveringConnectionIds: Set<UUID>guard.buildEffectiveConnectionsucceeded butdriver.connect()failed, the tunnel was orphaned. Added cleanup.Changes
DatabaseManager+Health.swiftreconnectDriverrebuilds SSH tunnel; returnsReconnectResultwith driver + effectiveConnection; cleans up tunnel on driver failureDatabaseManager+SSH.swiftrecoveringConnectionIds; 10 retries / 120s max; disconnect live driver not stale snapshotDatabaseManager.swiftrecoveringConnectionIds: Set<UUID>DatabaseManager+SystemEvents.swiftdidWakeNotification→ validates SSH tunnels on wakeAppDelegate.swiftstartObservingSystemEvents()SSHTunnelManager.swiftProcessInfo.beginActivityLibSSH2TunnelFactory.swiftSO_KEEPALIVE+TCP_KEEPALIVEon SSH sockets; nil password guardPasswordAuthenticator.swiftKeyboardInteractiveAuthenticator.swiftCHANGELOG.mdTest plan