diff --git a/src/main/java/ssh/CustomConnectionMonitor.java b/src/main/java/ssh/CustomConnectionMonitor.java index 6d38ded..f839b76 100644 --- a/src/main/java/ssh/CustomConnectionMonitor.java +++ b/src/main/java/ssh/CustomConnectionMonitor.java @@ -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. */ diff --git a/src/main/java/ssh/SSHTunnel.java b/src/main/java/ssh/SSHTunnel.java index 8d9e86c..7842dc8 100644 --- a/src/main/java/ssh/SSHTunnel.java +++ b/src/main/java/ssh/SSHTunnel.java @@ -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. + * + *

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. */