Skip to content

Add connection health monitoring with auto-reconnect#50

Merged
datlechin merged 1 commit intomainfrom
feat/connection-health-monitoring
Feb 12, 2026
Merged

Add connection health monitoring with auto-reconnect#50
datlechin merged 1 commit intomainfrom
feat/connection-health-monitoring

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

  • Add periodic health checks (30s SELECT 1 ping) for MySQL/MariaDB and PostgreSQL connections via a new ConnectionHealthMonitor actor
  • Auto-reconnect with exponential backoff (3 retries: 2s, 4s, 8s) when a health check fails
  • Toolbar Reconnect button (↻) appears when connection is in error or disconnected state for manual recovery
  • Store effectiveConnection on ConnectionSession so SSH-tunneled connections auto-reconnect through the tunnel (not directly to remote host)

Architecture

  • ConnectionHealthMonitor — new Swift actor with closure-based DI (mirrors SSHTunnelManager pattern), manages ping loop + retry state machine
  • DatabaseManager — stores monitors per session, creates/destroys on connect/disconnect, exposes reconnectCurrentSession() for manual reconnect
  • Toolbar — new .reconnect item with arrow.triangle.2.circlepath SF Symbol, enabled only in error/disconnected states

Files Changed

File Change
Core/Database/ConnectionHealthMonitor.swift NEW — Actor with ping loop, retry logic, state machine (229 lines)
Core/Database/DatabaseManager.swift Health monitor lifecycle, reconnectDriver() helper, reconnectCurrentSession()
Models/ConnectionSession.swift Added effectiveConnection for SSH tunnel awareness
Views/Toolbar/ToolbarItemIdentifier.swift Added .reconnect case
Views/Toolbar/ToolbarItemFactory.swift Added makeReconnectItem() + action proxy
Views/Toolbar/ToolbarController.swift Added reconnect to defaults + validation
Views/Main/MainContentNotificationHandler.swift Added .reconnectDatabase observer
OpenTableApp.swift Added .reconnectDatabase notification name

Test plan

  • Connect to MySQL via direct connection, kill mysqld, observe auto-reconnect in toolbar status
  • Connect via SSH tunnel, kill database process (not tunnel), verify auto-reconnect uses tunnel
  • After 3 failed retries, verify Reconnect button appears and is clickable
  • Click Reconnect button, verify manual reconnection works and schema reloads
  • Verify SQLite connections don't have health monitoring (no unnecessary pings)
  • Disconnect manually — verify health monitor stops cleanly

Periodic 30-second health checks (SELECT 1) for MySQL/MariaDB and
PostgreSQL connections with automatic exponential backoff reconnection
(3 retries at 2s/4s/8s intervals). Adds a toolbar Reconnect button
for manual recovery when auto-reconnect fails.
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