Skip to content

fix(ssh): close zombie local port forwarder on SSH keep-alive ping failures #1374

Description

@ZhuchkaTriplesix

Problem

In SshTunnelManager (lib/core/security/ssh_tunnel_manager.dart, lines 393–404):

Timer? keepAliveTimer;
if (config.keepAliveIntervalSeconds > 0) {
  keepAliveTimer = Timer.periodic(
    Duration(seconds: config.keepAliveIntervalSeconds),
    (_) {
      if (!client.isClosed) {
        client.ping().catchError((_) {});
      }
    },
  );
}
  1. Suppressed Ping Failures:
    When an SSH bastion drops (network blip, Wi-Fi reconnection, laptop sleep/wake, firewall state timeout), client.ping() fails, but .catchError((_) {}) suppresses the error without taking action.
  2. Zombie Local Forwarder:
    serverSocket continues listening on 127.0.0.1:localPort.
    When database drivers attempt to connect to 127.0.0.1:localPort, the local TCP handshake succeeds, but line 383 (client.forwardLocal(remoteHost, remotePort)) immediately fails and destroys the socket with clientSocket.destroy().
    The driver observes an immediate RST/EOF.
    Furthermore, until someone explicitly calls openTunnel again with the same pool key, the dead session remains in _sessions[poolKey].

Scope

  • In keepAliveTimer, track consecutive ping failures (e.g. 2–3 failed pings).
  • When pings fail consecutively, proactively close serverSocket and client, removing the session from _sessions.
  • Ensure new connection requests to that pool key dial a fresh SSH tunnel rather than reusing a zombie session.
  • Add unit tests simulating ping failure and verifying proactive session cleanup.

Activity

  1. added
    bugSomething isn't working
    stabilityTheme parser epic label: stability
    coreCore library logic and services
    connectionsDatabase connections, URI parsing, pools
    P2Medium priority / Parity & Refactoring
    on Oct 10, 2026
  2. ZhuchkaTriplesix commented on Oct 11, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Done in #1380 (merged into dev).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priority / Parity & RefactoringbugSomething isn't workingconnectionsDatabase connections, URI parsing, poolscoreCore library logic and servicesstabilityTheme parser epic label: stability

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions