[sshd] Fix calculation of timeout in AbstractClientProxyConnector
The previous implementation mixed nano seconds (elapsed) and milli seconds (remaining) without conversion. Change-Id: I9e1654afa47fa32c94808af3b2dd0418a372fb00
This commit is contained in:
parent
9be2b7f8a8
commit
47ecb0096e
|
@ -27,8 +27,8 @@
|
||||||
public abstract class AbstractClientProxyConnector
|
public abstract class AbstractClientProxyConnector
|
||||||
implements StatefulProxyConnector {
|
implements StatefulProxyConnector {
|
||||||
|
|
||||||
private static final long DEFAULT_PROXY_TIMEOUT_MILLIS = TimeUnit.SECONDS
|
private static final long DEFAULT_PROXY_TIMEOUT_NANOS = TimeUnit.SECONDS
|
||||||
.toMillis(30L);
|
.toNanos(30L);
|
||||||
|
|
||||||
/** Guards {@link #done} and {@link #bufferedCommands}. */
|
/** Guards {@link #done} and {@link #bufferedCommands}. */
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
|
@ -39,7 +39,7 @@ public abstract class AbstractClientProxyConnector
|
||||||
|
|
||||||
private AtomicReference<Runnable> unregister = new AtomicReference<>();
|
private AtomicReference<Runnable> unregister = new AtomicReference<>();
|
||||||
|
|
||||||
private long remainingProxyProtocolTime = DEFAULT_PROXY_TIMEOUT_MILLIS;
|
private long remainingProxyProtocolTime = DEFAULT_PROXY_TIMEOUT_NANOS;
|
||||||
|
|
||||||
private long lastProxyOperationTime = 0L;
|
private long lastProxyOperationTime = 0L;
|
||||||
|
|
||||||
|
@ -85,12 +85,12 @@ public AbstractClientProxyConnector(@NonNull InetSocketAddress proxyAddress,
|
||||||
* to initialize for
|
* to initialize for
|
||||||
*/
|
*/
|
||||||
protected void init(ClientSession session) {
|
protected void init(ClientSession session) {
|
||||||
remainingProxyProtocolTime = session.getLongProperty(
|
long millis = session.getLongProperty(
|
||||||
StatefulProxyConnector.TIMEOUT_PROPERTY,
|
StatefulProxyConnector.TIMEOUT_PROPERTY,
|
||||||
DEFAULT_PROXY_TIMEOUT_MILLIS);
|
0);
|
||||||
if (remainingProxyProtocolTime <= 0L) {
|
remainingProxyProtocolTime = (millis > 0)
|
||||||
remainingProxyProtocolTime = DEFAULT_PROXY_TIMEOUT_MILLIS;
|
? TimeUnit.MILLISECONDS.toNanos(millis)
|
||||||
}
|
: DEFAULT_PROXY_TIMEOUT_NANOS;
|
||||||
if (session instanceof JGitClientSession) {
|
if (session instanceof JGitClientSession) {
|
||||||
JGitClientSession s = (JGitClientSession) session;
|
JGitClientSession s = (JGitClientSession) session;
|
||||||
unregister.set(() -> s.setProxyHandler(null));
|
unregister.set(() -> s.setProxyHandler(null));
|
||||||
|
@ -115,12 +115,9 @@ protected long getTimeout() {
|
||||||
if (last != 0L) {
|
if (last != 0L) {
|
||||||
long elapsed = now - last;
|
long elapsed = now - last;
|
||||||
remaining -= elapsed;
|
remaining -= elapsed;
|
||||||
if (remaining < 0L) {
|
remainingProxyProtocolTime = remaining;
|
||||||
remaining = 10L; // Give it grace period.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
remainingProxyProtocolTime = remaining;
|
return Math.max(remaining / 1_000_000L, 10L); // Give it grace period.
|
||||||
return remaining;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue