Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/main/java/ssh/CustomConnectionMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ public class CustomConnectionMonitor {

private static final Logger LOG = Logger.getLogger(CustomConnectionMonitor.class.getName());

static final long CURRENT_RETRY_DELAY = 5000;
static final int MAX_RETRIES = 30;
/**
* Between reconnect attempts while the network is down: the first one that can get through
* should not wait long once it is back (5 s -> 2 s took 2010's return after a 20-second outage
* from 25.1 s to 23.6 s). MAX_RETRIES keeps the ~150 s before the tunnel is rebuilt.
*/
static final long CURRENT_RETRY_DELAY = 2000;
static final int MAX_RETRIES = 75;
/**
* The first reconnect goes out after this long, not after the full retry delay: the session
* has already been gone for the keepalive's ~15 seconds, and every second more is a second
* of failing tests.
*/
static final long FIRST_RETRY_DELAY = 1000;
static final long FIRST_RETRY_DELAY = 250;
/** Between re-requests of the reverse forward on a session that is up. */
static final long FORWARD_RETRY_DELAY = 2000;
/** About two minutes of re-requests before the tunnel is rebuilt. */
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/ssh/SSHTunnel.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,18 @@ public class SSHTunnel implements ReconnectableTunnel {
* so after a NAT change or a laptop switching networks the session looked connected until the
* operating system gave up retransmitting -- about 15 minutes on Linux -- and all that time
* the tunnel server kept port 2010 for a client that was gone.
*
* <p>2 s x 3: a session that hears nothing at all from the server for ~6 s is dead. That is
* the floor of how fast port 2010 can come back after a network change, so it is kept short;
* the server answers every keepalive at once, so a healthy connection - busy or idle - is
* never that quiet. Measured on a NAT change: 2010 back after ~8 s (5 s x 3: ~18 s); a
* 4-second outage passes without a reconnect, and nothing reconnected under load.
*/
static final int SERVER_ALIVE_INTERVAL_MS = 5_000;
static final int SERVER_ALIVE_INTERVAL_MS = 2_000;
static final int SERVER_ALIVE_COUNT_MAX = 3;

/** How often the connection and forwarding monitors look. */
static final long CONNECTION_CHECK_INTERVAL_MS = 2_000;
static final long CONNECTION_CHECK_INTERVAL_MS = 500;
static final long FORWARDING_CHECK_INTERVAL_MS = 5_000;

/** How long one end-to-end probe of the reverse forward may take. */
Expand Down
Loading