Skip to content

fix(ios): ask the SSH host key question from the screen that owns the connect attempt - #3002

Merged
datlechin merged 4 commits into
mainfrom
fix/ios-ssh-host-key-prompt
Sep 20, 2026
Merged

datlechin merged 4 commits into
mainfrom
fix/ios-ssh-host-key-prompt

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

On iPhone and iPad, connecting over SSH to a server whose host key is new brought up the "Trust" alert and then closed it again in under a second, with no answer from the user. Every connect after that hung on Connecting… or dropped back to the connection list, and nothing short of relaunching the app helped. Reported against TestFlight build 22.

Root cause

The question was one app-wide alert (HostKeyPromptPresenter.shared) attached to the root of the window, and the open connection is a fullScreenCover presented from that same root. One presenter cannot do both.

Measured on the iOS 27 simulator against a real sshd, with the app's own log:

  • Asked while the cover was still animating in, UIKit refused the alert ("Attempt to present … which is already presenting"). The alert never appeared, pending stayed set and its continuation was never resumed.
  • Asked once the cover was up, SwiftUI dismissed the cover to show the alert (openConnection set -> nil, which is the drop back to the list), and the cover's re-presentation then tore the alert down. The dismiss binding counted that as Cancel: the ~0.87 second flash, in 4 of 7 runs.

Two things then turned a lost question into a permanent hang:

  • ConnectionCoordinator.connect() joined any in-flight attempt with no bound, the coordinator outlives the cover, and the back button never cancelled. Each reopen logged joins in-flight task and sat on Connecting for 25 seconds at a time.
  • ask() refused every later request while one was pending, so the next unknown-host connect failed instantly with "host key was not trusted" and no prompt.

Microsoft Entra sign-in had the same shape and the same defect.

The fix

The question now belongs to the connect attempt, and the screen that owns the attempt shows it.

  • The driver layer states the question, not the wording. TableProDatabase gains ConnectionQuestion (.unknownHostKey, .changedHostKey) and a ConnectionPrompter, threaded through ConnectionManager.connect(_:prompter:) and SSHProvider.createTunnel. HostKeyVerifier asks it; the wording and the buttons live in the app.
  • ConnectionPromptQueue, one per ConnectionCoordinator and one for Test Connection, holds the questions in order, never refuses a second one, and answers every waiter. A question asked by an already-cancelled attempt is never shown; cancelling or retiring the attempt answers what is pending, so no tunnel is left suspended.
  • ConnectedView presents them with .connectionPrompts(coordinator.prompts) inside the cover. Measured: an alert attached there waits for the cover to finish presenting, never dismisses it, and survives a root sheet, background and foreground, and the app-lock window. The alert holds the question it presented, so a dismissal answers what the user was looking at, and an externally emptied queue takes the alert down instead of leaving dead buttons.
  • Every attempt ends. Callers awaiting an attempt are tracked by id (AttemptJoiners), so the last screen to leave abandons it while a screen replaced by another does not; the Connections button cancels; and cancelConnect() answers pending questions even for a reconnect or a database switch, which own no connectTask.
  • No screen, no hang. With no prompter (Shortcuts, Siri, widgets) an unknown or changed key fails at once with a message naming what to do, and the two cases read differently.
  • The two singletons and both root-level modifiers are gone.

Verification

  • The original reproduction, re-run against the fix on the iOS 27 simulator with a real sshd, before and after, logs in sshrepro/runs/:
    • Before: the cover self-dismissed 1.1s in with the question still pending; attempts 2 to 4 each joined the stuck attempt and showed Connecting for 25s.
    • After, re-run on these three commits: the alert stayed up for 67s across a background and foreground cycle, with the cover intact. Trust connects (tunnel forwarding started, then connected). A dismissal the user did not cause answers the question and ends the attempt inline with Retry, leaving no suspended tunnel; three further connects each asked and answered cleanly, including through a 2.5s delay proxy and a 20s stall, with nothing left pending.
  • iOS test target: 683 passed, 0 failed. TableProDatabaseTests: 30 passed. New tests cover the queue (answer, cancel before and during the wait, retire, ordering, notices, a stale notice), the verifier (trust only on an explicit yes, refuse, changed key, no prompter fails at once), the joiner count, and that the prompter reaches the tunnel.
  • SwiftLint strict on every touched file, both docs checks, and the string catalog check pass. The two new messages are translated into Vietnamese, Korean, Simplified and Traditional Chinese.
  • Reviewed by a second model for correctness and again for security. The security review found no vulnerabilities; both rounds of findings are fixed in the follow-up commits.

Not verified on a device or an older runtime: iOS 18 to 26 (only the iOS 27 runtime is installed here). One case has unit tests only: retiring an attempt while its question is on screen. The alert is modal, so nothing in the app can reach that path from the simulator, and every route tried (background and foreground, an edit, a sample reset, a deep link) either never cancels or is intercepted by the system first.

Deliberately not fixed here

Found while investigating, each with a reproduction, none of them the reported bug:

  • The SSH relay reads the channel only when the socket polls readable, so bytes libssh2 already queued wait for the next wakeup: about 30 seconds per extra 32KB. macOS fixed this in Connecting to MySQL hosted on Render.com via docker - (SQLSTATE: HY000) #1883 by pumping on a poll timeout. This is the one to do next, because a large schema can still make a connection look stuck.
  • A failed SSH connect leaks its socket and libssh2 session (everything after connect except host-key rejection).
  • ConnectionManager.connect awaits the previous session's teardown with no deadline.
  • Each live tunnel's accept loop holds a Swift concurrency thread for as long as it lives.
  • A connection restored at launch starts connecting behind the app lock.
  • jumpHosts is ignored on iOS, so a connection that reaches its database through a bastion dials the target directly.

@mintlify

mintlify Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
TablePro 🟢 Ready View Preview Sep 20, 2026, 3:21 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

This branch was successfully deployed

1 active deployment
staging - docs — 25271d0b Deployed Sep 20, 2026 by mintlify[bot]
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