diff options
author | Stephan Wahlbrink <sw@wahlbrink.eu> | 2023-03-06 10:33:24 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2023-03-06 23:45:18 +0100 |
commit | 47ecb0096ea770e219d82432178860a557b1ff9a (patch) | |
tree | 5cfaff6fc5f238f9413bb1100c26c6b49bebacec /org.eclipse.jgit.ssh.apache | |
parent | 9be2b7f8a885926fa3d4f6e444223034106e6711 (diff) | |
download | jgit-47ecb0096ea770e219d82432178860a557b1ff9a.tar.gz jgit-47ecb0096ea770e219d82432178860a557b1ff9a.zip |
[sshd] Fix calculation of timeout in AbstractClientProxyConnector
The previous implementation mixed nano seconds (elapsed) and milli
seconds (remaining) without conversion.
Change-Id: I9e1654afa47fa32c94808af3b2dd0418a372fb00
Diffstat (limited to 'org.eclipse.jgit.ssh.apache')
-rw-r--r-- | org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/AbstractClientProxyConnector.java | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/AbstractClientProxyConnector.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/AbstractClientProxyConnector.java index a8e33af35e..a05d6415fa 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/AbstractClientProxyConnector.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/proxy/AbstractClientProxyConnector.java @@ -27,8 +27,8 @@ import org.eclipse.jgit.internal.transport.sshd.JGitClientSession; public abstract class AbstractClientProxyConnector implements StatefulProxyConnector { - private static final long DEFAULT_PROXY_TIMEOUT_MILLIS = TimeUnit.SECONDS - .toMillis(30L); + private static final long DEFAULT_PROXY_TIMEOUT_NANOS = TimeUnit.SECONDS + .toNanos(30L); /** Guards {@link #done} and {@link #bufferedCommands}. */ private final Object lock = new Object(); @@ -39,7 +39,7 @@ public abstract class AbstractClientProxyConnector private AtomicReference<Runnable> unregister = new AtomicReference<>(); - private long remainingProxyProtocolTime = DEFAULT_PROXY_TIMEOUT_MILLIS; + private long remainingProxyProtocolTime = DEFAULT_PROXY_TIMEOUT_NANOS; private long lastProxyOperationTime = 0L; @@ -85,12 +85,12 @@ public abstract class AbstractClientProxyConnector * to initialize for */ protected void init(ClientSession session) { - remainingProxyProtocolTime = session.getLongProperty( + long millis = session.getLongProperty( StatefulProxyConnector.TIMEOUT_PROPERTY, - DEFAULT_PROXY_TIMEOUT_MILLIS); - if (remainingProxyProtocolTime <= 0L) { - remainingProxyProtocolTime = DEFAULT_PROXY_TIMEOUT_MILLIS; - } + 0); + remainingProxyProtocolTime = (millis > 0) + ? TimeUnit.MILLISECONDS.toNanos(millis) + : DEFAULT_PROXY_TIMEOUT_NANOS; if (session instanceof JGitClientSession) { JGitClientSession s = (JGitClientSession) session; unregister.set(() -> s.setProxyHandler(null)); @@ -115,12 +115,9 @@ public abstract class AbstractClientProxyConnector if (last != 0L) { long elapsed = now - last; remaining -= elapsed; - if (remaining < 0L) { - remaining = 10L; // Give it grace period. - } + remainingProxyProtocolTime = remaining; } - remainingProxyProtocolTime = remaining; - return remaining; + return Math.max(remaining / 1_000_000L, 10L); // Give it grace period. } /** |