trukhinyuri commented on code in PR #930:
URL: https://github.com/apache/mina-sshd/pull/930#discussion_r4277750135
##########
sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java:
##########
@@ -249,6 +249,40 @@ public Result process(ConnectionService connectionService,
String request, boole
}
}
+ // see GH-929
+ @Test
+ void testPerSessionHeartbeatConfiguration() throws Exception {
+ CoreModuleProperties.IDLE_TIMEOUT.set(sshd, Duration.ofSeconds(30));
+ List<RequestHandler<ConnectionService>> globalHandlers =
sshd.getGlobalRequestHandlers();
+ sshd.setGlobalRequestHandlers(Collections.singletonList(new
AbstractConnectionServiceRequestHandler() {
+ @Override
+ public Result process(ConnectionService connectionService, String
request, boolean wantReply, Buffer buffer)
+ throws Exception {
+ // Never reply;
+ return Result.Replied;
+ }
Review Comment:
Clarified the comment above `return Result.Replied;` in 97389fd1: returning
`Result.Replied` without writing a buffer suppresses
`AbstractSession.requestSuccess()` so the client receives no reply and
exercises the `heartbeatMaxNoReply` disconnect path.
##########
sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java:
##########
@@ -47,9 +47,9 @@
public class ClientConnectionService
extends AbstractConnectionService
implements ClientSessionHolder {
- protected final String heartbeatRequest;
- protected final Duration heartbeatInterval;
- protected final int heartbeatMaxNoReply;
+ protected String heartbeatRequest;
+ protected Duration heartbeatInterval;
+ protected int heartbeatMaxNoReply;
Review Comment:
Declared `heartbeatRequest`, `heartbeatInterval`, and `heartbeatMaxNoReply`
as `volatile` in 97389fd1 so updates in `startHeartBeat()` are safely published
to the heartbeat scheduler thread.
##########
sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java:
##########
@@ -122,6 +122,9 @@ public void start() {
@Override
protected synchronized ScheduledFuture<?> startHeartBeat() {
+ heartbeatRequest =
CoreModuleProperties.HEARTBEAT_REQUEST.getRequired(this);
+ heartbeatInterval =
CoreModuleProperties.HEARTBEAT_INTERVAL.getRequired(this);
+ heartbeatMaxNoReply = configureMaxNoReply();
Review Comment:
Addressed in 97389fd1 by marking all three heartbeat fields `volatile`.
##########
sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java:
##########
@@ -249,6 +249,40 @@ public Result process(ConnectionService connectionService,
String request, boole
}
}
+ // see GH-929
+ @Test
+ void testPerSessionHeartbeatConfiguration() throws Exception {
+ CoreModuleProperties.IDLE_TIMEOUT.set(sshd, Duration.ofSeconds(30));
+ List<RequestHandler<ConnectionService>> globalHandlers =
sshd.getGlobalRequestHandlers();
+ sshd.setGlobalRequestHandlers(Collections.singletonList(new
AbstractConnectionServiceRequestHandler() {
+ @Override
+ public Result process(ConnectionService connectionService, String
request, boolean wantReply, Buffer buffer)
+ throws Exception {
+ // Never reply;
+ return Result.Replied;
+ }
+ }));
+ Duration heartbeat = Duration.ofMillis(500L);
+ try (ClientSession session = client.connect(getCurrentTestName(),
TEST_LOCALHOST, port).verify(CONNECT_TIMEOUT)
+ .getSession()) {
+ CoreModuleProperties.HEARTBEAT_INTERVAL.set(session, heartbeat);
+ CoreModuleProperties.HEARTBEAT_NO_REPLY_MAX.set(session, 1);
+ session.addPasswordIdentity(getCurrentTestName());
+ session.auth().verify(AUTH_TIMEOUT);
+
+ try (ClientChannel channel =
session.createChannel(Channel.CHANNEL_SHELL)) {
Review Comment:
Added `channel.open().verify(OPEN_TIMEOUT)` before
`channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), ...)` in 97389fd1.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]