Skip to content

perf(connections): reconnect when the network returns and ping less while inactive - #4582

Open
datlechin wants to merge 3 commits into
mainfrom
perf/reconnect-on-network-return
Open

datlechin wants to merge 3 commits into
mainfrom
perf/reconnect-on-network-return

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • A session's reconnect loop now follows the network path (NWPathMonitor). While the path is down, a connection that leaves this Mac waits for it instead of spending attempts, and an attempt the path dropped under is not counted. When the path comes back, or moves to other interfaces (a Wi-Fi rejoin, a VPN), every waiting loop's backoff sleep is cut short and it redials at once. Backoff still applies to a server that refuses. A server on loopback or a local socket keeps redialing with no path.
  • A path change and a wake from sleep now check direct sessions too, not only tunneled ones.
  • While the app is inactive, the health check waits at least ConnectionHealthCheck.freshness (300 s) between pings; verifyBeforeUse covers the return. Monitors start again on didBecomeActive, back on the configured interval. The monitor reads the interval once per pass.
  • The ping is a turn on the session driver gate, and is skipped while the gate is held: the work holding it reports a dead connection itself.

Measured with the unit tests: with the path down, a loop that has waited out its backoff dials nothing and waits for the path, where it used to spend an attempt each step until all 10 were gone (noAttemptWhileThePathIsDown); a path return redials without waiting out the backoff (pathReturnRetriesAtOnce). In the background, 10 connections on the default setting ping at most once per connection per 300 s, from about 20 pings a minute. The Wi-Fi-off timings were not run here.

Test plan

  • SessionRecoveryNetworkTests (new): no attempt while the path is down, an immediate redial on path return and on an interface change, loopback ignores the path, the inactive interval, and the gated ping. Each fails on main.
  • Local run: SessionRecoveryNetworkTests, SessionRecoveryLoopTests, ConnectionHealthMonitorHandoffTests, ConnectionHealthMonitorRetryTests, ReconnectDegradationTests: 55 executed, 55 passed.

Closes #4546

…hile inactive

Recovery loops follow NWPathMonitor: they wait for the path instead of spending attempts and redial at once when it comes back or changes interface. A path change and a wake check direct sessions too; the health interval stretches to the freshness window while the app is inactive; the ping is a turn on the session driver gate.

This branch has not been deployed

No deployments
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.

perf(connections): reconnect when the network returns and ping less while inactive

1 participant