Repository navigation
Done
Labels
Description
Problem
- After a Wi-Fi drop or a VPN reconnect, a session can wait up to 120 s after the network is back before it reconnects. Attempts made while the network is down count against the 10-attempt budget, so an outage of about 8 minutes or more leaves the session unreachable even though nothing is wrong with the server. Outages under about 30 s recover within a few seconds.
- On wake, only tunneled sessions are checked; direct sessions wait for first use.
- The default health check pings every connection every 30 s, also while the app sits in the background: about 20 pings a minute with 10 connections. It keeps serverless databases awake and wakes the network.
- The ping runs outside the session driver gate, so a table open or query that starts during a ping waits up to one RTT behind it.
Cause
runRecoverysleepsExponentialBackoff.delay(for:maxDelay:)between attempts, capped bymaxRecoveryDelay = 120(apple/TablePro/Core/Database/DatabaseManager+Recovery.swift:44,:162-184). The delays are 2, 4, 8, 16, 32, 64, then 120 s (apple/Packages/TableProMacCore/Sources/TableProUtilities/Connection/ExponentialBackoff.swift:3-14), and the budget ismaxAttempts = 10(apple/TablePro/Models/Connection/ConnectionWindowPhase.swift:105). Nothing wakes the sleep when the path comes back.- The only
NWPathMonitorisSyncNetworkMonitor, used for iCloud sync (apple/Packages/TableProCore/Sources/TableProSyncTransport/SyncNetworkMonitor.swift:10-33).DatabaseManagerhas no reachability input. handleSystemDidWakevalidates tunneled sessions only (apple/TablePro/Core/Database/DatabaseManager+SystemEvents.swift:22-40).- The default is
.every30Seconds(apple/TablePro/Models/Settings/GeneralSettings.swift:79). The monitor sleeps a fixed interval and reads the interval from settings on the main actor twice per pass (apple/TablePro/Core/Database/ConnectionHealthMonitor.swift:69-90). Nothing depends on whether the app is active, thoughverifyBeforeUsealready checks a connection older than 300 s when the user reaches for it (apple/TablePro/Core/Database/DatabaseManager+Verification.swift:38-56,apple/TablePro/Models/Settings/ConnectionHealthCheck.swift:29). - The ping handler skips only while
queriesInFlightis set at that instant, then callsmainDriver.ping()directly (apple/TablePro/Core/Database/DatabaseManager+Health.swift:41-60,:54). The driver runs it on the same queue as user work (apple/Plugins/PostgreSQLDriverPlugin/LibPQDriverCore.swift:286-291).
Overlaps #4462: WI13 already covers counting an answered statement as a connection check, so a busy connection skips the ping. This issue adds the network wake-up, the inactive interval and the gate.
Change
- Generalize
SyncNetworkMonitorinto one path monitor thatDatabaseManageralso observes (Network framework, the documented reachability API). While the path is unsatisfied, recovery loops wait without spending attempts. When it becomes satisfied, or its interface changes, cancel every waiting loop's sleep so each retries at once. Backoff still applies to real server failures. - On a path change and on wake, check direct sessions as well as tunneled ones.
- While
NSAppis inactive, stretch the health-check interval toConnectionHealthCheck.freshnessand letverifyBeforeUsecover the return; restore the configured interval ondidBecomeActive. Read the interval once per pass. - Send the ping as a turn on the session driver gate. When the gate is held, skip the ping: the work holding it reports a dead connection itself.
- SSH keepalive stays in
LibSSH2KeepAlive.
Measure
- 5 connections open, Wi-Fi off for 3 minutes, then on: time from path satisfied to every session live. Today up to 120 s; target about one connect time. Repeat with a 10-minute outage: no session ends unreachable.
- 10 connections, app in the background for 15 minutes: pings per minute from signposts or the server log, and idle wake-ups in Activity Monitor. Today about 20 pings a minute; target at most one per connection per 300 s.
- A query started during a ping: no wait behind it (signpost on the gate turn).
Part of the performance plan.
Activity
datlechin commentedon Nov 25, 2026
#4582 ships the network wake-up, the direct-session checks on path change and wake, the inactive interval, the single interval read and the gated ping. Notes:
ConnectionNetworkMonitorrather than a generalizedSyncNetworkMonitor: that one lives inTableProSyncTransport, which the iOS app links too, and reports only a return to a usable path, where a reconnect also needs an interface change. Folding the two into one monitor is left for a follow-up.