Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset the sequence numbers on Session disconnect to support reconnection #409

Conversation

mvegter
Copy link
Contributor

@mvegter mvegter commented Oct 21, 2023

Resolves #408

@mvegter mvegter force-pushed the mvegter-patch-reset-sequence-numbers-to-allow-reconnection branch from e91a9a7 to 04cc27c Compare October 21, 2023 11:34
@mvegter
Copy link
Contributor Author

mvegter commented Oct 21, 2023

Can also be reproduced by changing any of the Algorithms IT to do :

    try {
      session.connect(timeout);
      assertTrue(session.isConnected());

      // Verify reconnect
      session.disconnect();
      session.connect(timeout);
      assertTrue(session.isConnected());

    } finally {
      session.disconnect();
    }

@mvegter mvegter force-pushed the mvegter-patch-reset-sequence-numbers-to-allow-reconnection branch 2 times, most recently from 751029b to 7643815 Compare October 21, 2023 17:19
@mvegter mvegter force-pushed the mvegter-patch-reset-sequence-numbers-to-allow-reconnection branch from 7643815 to d299535 Compare October 23, 2023 12:56
String pubkeyAcceptedAlgorithms = session.getConfig("PubkeyAcceptedAlgorithms") + ",ssh-rsa";
session.setConfig("server_host_key", serverHostKey);
session.setConfig("PubkeyAcceptedAlgorithms", pubkeyAcceptedAlgorithms);
doSftp(session, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should wrap this in a assertDoesNotThrow() to emphasize that we expect this to succeed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test already fails if an Exception is thrown, so right now it is indeed implied. Let me know if you want that changed or not , i don't really see that as a common pattern in the current ITs

Copy link
Contributor

@norrisjeremy norrisjeremy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't be surprised if the intention was for the Session object to not be reusable to create a new connection after the disconnect method has been called. Why not instead simply create a new Session object instead of trying to reuse the existing one?

Also considering this isn't a regression per se (since JSch has behaved in this manner for years), I would lean more towards not merging this in, since there is always a chance that this could instead introduce a some other new regression of some sort instead.

@mwiede what do you think?

@mvegter
Copy link
Contributor Author

mvegter commented Oct 23, 2023

I wouldn't be surprised if the intention was for the Session object to not be reusable to create a new connection after the disconnect method has been called. Why not instead simply create a new Session object instead of trying to reuse the existing one?

I understand your position on this change, however the reason for introducing this is that the Session already resets the isConnected flag. This technically allows anyone to call connect() again , whereas a connected session throws an Exception if we attempt to re-connect. If we were to disallow this I would expect (perhaps in a future change) to throw an Exception when calling connect() after a disconnect()

On another note, allowing a client to call connect() multiple times can also allow for more resilience with retries on certain IOException without setting up a new Jsch/Session .

Copy link
Contributor

@norrisjeremy norrisjeremy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly enough about this to block it, as long as @mwiede is also ok with it.

@mwiede
Copy link
Owner

mwiede commented Oct 25, 2023

we do not really know, whether the Session was intened for re-use or not, but I think we can accept this change, because it also cannot be seen in the code, that reuse has to be blocked.

@mwiede mwiede merged commit 31245e2 into mwiede:master Oct 25, 2023
3 checks passed
@mvegter mvegter deleted the mvegter-patch-reset-sequence-numbers-to-allow-reconnection branch October 28, 2023 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reconnecting after JSchAlgoNegoFailException with new server_host_key results in corrupt packets
3 participants