Skip to content

Notice a dead session in ~6 s instead of ~15, and reconnect sooner - #71

Merged
jochen-testingbot merged 1 commit into
mainfrom
fix/faster-dead-session-detection
Oct 25, 2026
Merged

jochen-testingbot merged 1 commit into
mainfrom
fix/faster-dead-session-detection

Conversation

@jochen-testingbot

Copy link
Copy Markdown
Contributor

What was wrong

With #69, port 2010 came back ~18 s after a customer's network change. Almost all of that was detection:

step time
JSch ServerAliveInterval 5 s × 3: silence before the session is dropped ~15 s
ConnectionMonitorTask noticing (every 2 s) ≤ 2 s
first reconnect delay 1 s
reconnect + forwards (the tunnel server frees 2010 at login) ~0.6 s

What changed

  • ServerAliveInterval 2 s × 3. A session that hears nothing from the server for ~6 s is dead. The server answers every keepalive at once, so a healthy connection, busy or idle, is never that quiet.
  • Faster reaction. The connection check runs every 500 ms, and the first reconnect goes out after 250 ms.
  • Retries 2 s apart (was 5 s) while the network is still down. The first attempt that can get through no longer waits up to 5 s once the network is back. MAX_RETRIES 30 → 75 keeps the ~150 s before the tunnel is rebuilt.

Tests

  • mvn test: 1042 tests, 0 failures.
  • End to end with tunnel-harness against a real tunnel VM:
scenario main (#69) this PR
NAT change, old flow blackholed on both ends ~18–24 s 8 s (first reconnect)
4 s outage — no reconnect
20 s outage 25.1 s 23.6 s
full proxy suite (35 checks) — 35/35, no reconnects
perf suite at 50 ms (downloads, uploads, 300-request burst) — no reconnects

The trade-off is deliberate: a network that is completely silent for 6 s or more (a Wi-Fi handover, for example) now gets a reconnect, about 1 s. Before, it got either 15 s of silence followed by the same reconnect, or a session that recovered by itself.

After a network change port 2010 came back ~18 s later. Nearly all of
that was detection: JSch's ServerAliveInterval at 5 s x 3 is ~15 s of
silence before the session is dropped. Then the connection check (every
2 s) and the first reconnect (after 1 s); the reconnect itself takes
~0.6 s.

- ServerAliveInterval 2 s x 3: a session that hears nothing from the server
  for ~6 s is dead. The server answers keepalives at once, so a healthy
  connection, busy or idle, is never that quiet.
- Connection check every 500 ms. First reconnect after 250 ms.
- Retries 2 s apart while the network is still down, so the first attempt
  that can get through does not wait long once it is back. 75 retries keep
  the ~150 s before the tunnel is rebuilt.

Measured against a real tunnel VM:
- NAT change (old flow blackholed on both ends): 2010 back after 8 s, was
  ~18-24 s.
- 4 s outage: no reconnect.
- 20 s outage: 23.6 s, was 25.1 s.
- Full proxy suite and perf suite (downloads, uploads, a 300-request burst):
  no reconnects.
@jochen-testingbot
jochen-testingbot merged commit 9433086 into main Oct 25, 2026
10 checks passed
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