hierynomus / sshj

ssh, scp and sftp for java
Apache License 2.0
2.46k stars 594 forks source link

Don't send keep alive signals before kex is done #934

Closed hpoettker closed 2 months ago

hpoettker commented 3 months ago

The PR should address #933.

codecov-commenter commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 69.16%. Comparing base (03f8b22) to head (f3954b8). Report is 2 commits behind head on master.

:exclamation: Current head f3954b8 differs from pull request most recent head cb3f4ee. Consider uploading reports for the commit cb3f4ee to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #934 +/- ## ============================================ + Coverage 68.96% 69.16% +0.19% - Complexity 1448 1454 +6 ============================================ Files 208 208 Lines 7602 7604 +2 Branches 658 660 +2 ============================================ + Hits 5243 5259 +16 + Misses 2009 1995 -14 Partials 350 350 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

derklaro commented 3 months ago

I think there is a difference between waiting for conn.equals(conn.getTransport().getService()) and isKexDone: the first version also awaits the authentication process to complete, the new solution just waits for the key exchange. I guess it's better to just wait until the auth is done as well, before sending out keep alive messages 🤷

hpoettker commented 3 months ago

I've added a reproducing test case to StrictKeyExchangeTest which uses a KeepAlive that sends heart beats instantantiouly after being started.

I've also relaxed the assertions in StrictKeyExchangeTest to prevent it from tripping on odd orders in the underlying concurrent processes.

The originally proposed changed should also work. But I've now made a simpler change, i.e. only starting the keep alive thread after the key exchange is done.

hierynomus commented 2 months ago

Thanks for the PR!