This is an automated email from the ASF dual-hosted git repository.
twolf pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git
The following commit(s) were added to refs/heads/master by this push:
new 99246d694 Fix ClientChannelEvent.Timeout and
ClientSessionEvent.TIMEOUT (#790)
99246d694 is described below
commit 99246d694de253a95998357244345bf0a2ef7af9
Author: Konstantin <[email protected]>
AuthorDate: Wed Jul 30 18:19:24 2025 +0200
Fix ClientChannelEvent.Timeout and ClientSessionEvent.TIMEOUT (#790)
Fix AbstractClientChannel.waitFor() and ClientSessionImpl.waitFor(); they
could time-out much too early.
On some hosts, on which waiting for the `futureLock.wait(remWait)` is
faster than 1 millisecond, `remWait` gets reduced by 123 milliseconds although
not even one passed. This causes a `ClientChannelEvent.Timeout` or
`ClientSessionEvent.TIMEOUT` after a much smaller time passed than the
configured timeout.
With these changes, the `remWait` is calculated based on the milliseconds
passed instead of transformed nanoseconds.
---
.../org/apache/sshd/client/channel/AbstractClientChannel.java | 10 +---------
.../java/org/apache/sshd/client/session/ClientSessionImpl.java | 10 +---------
2 files changed, 2 insertions(+), 18 deletions(-)
diff --git
a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
index fd12580de..16ea1de72 100644
---
a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
+++
b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
@@ -27,7 +27,6 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.Objects;
import java.util.Set;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
@@ -262,6 +261,7 @@ public abstract class AbstractClientChannel extends
AbstractChannel implements C
if (timeout > 0L) {
long now = System.currentTimeMillis();
long usedTime = now - startTime;
+ remWait = timeout - usedTime;
if ((usedTime >= timeout) || (remWait <= 0L)) {
if (traceEnabled) {
log.trace("waitFor({}) call timeout {}/{} for
mask={}: {}",
@@ -290,14 +290,6 @@ public abstract class AbstractClientChannel extends
AbstractChannel implements C
if (traceEnabled) {
log.trace("waitFor({}) lock notified on channel after
{} nanos", this, nanoDuration);
}
-
- if (timeout > 0L) {
- long waitDuration =
TimeUnit.MILLISECONDS.convert(nanoDuration, TimeUnit.NANOSECONDS);
- if (waitDuration <= 0L) {
- waitDuration = 123L;
- }
- remWait -= waitDuration;
- }
} catch (InterruptedException e) {
long nanoEnd = System.nanoTime();
long nanoDuration = nanoEnd - nanoStart;
diff --git
a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
index cb5b298dc..f4e3c576d 100644
---
a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
+++
b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
@@ -28,7 +28,6 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
@@ -266,6 +265,7 @@ public class ClientSessionImpl extends
AbstractClientSession {
if (timeout > 0L) {
long now = System.currentTimeMillis();
long usedTime = now - startTime;
+ remWait = timeout - usedTime;
if ((usedTime >= timeout) || (remWait <= 0L)) {
if (traceEnabled) {
log.trace("waitFor({}) call timeout {}/{} for
mask={}: {}",
@@ -294,14 +294,6 @@ public class ClientSessionImpl extends
AbstractClientSession {
if (traceEnabled) {
log.trace("waitFor({}) Lock notified after {} nanos",
this, nanoDuration);
}
-
- if (timeout > 0L) {
- long waitDuration =
TimeUnit.MILLISECONDS.convert(nanoDuration, TimeUnit.NANOSECONDS);
- if (waitDuration <= 0L) {
- waitDuration = 123L;
- }
- remWait -= waitDuration;
- }
} catch (InterruptedException e) {
long nanoEnd = System.nanoTime();
long nanoDuration = nanoEnd - nanoStart;