-
Notifications
You must be signed in to change notification settings - Fork 671
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
Properly close connection on EOF #1111
base: master
Are you sure you want to change the base?
Conversation
I'm not sure that this is the correct behavior, especially if the local side still wants to send data. The EOF from the server just means it will send no more data. If we send a channel close request to the server, it should send a close event back.... AFAIK that's what |
@mscdex This is changing the server response to the client. The client sends |
There is definitely a bug in the server implementation. It is easy to reproduce as #1029 detailed. It's possible that this change is negatively affecting the client implementation as I have only been using this as a server. Perhaps there is a better place to handle this @mscdex? This is the relevant part of the spec: https://datatracker.ietf.org/doc/html/rfc4254#section-5.3 |
@mscdex The change has been updated to only operate this way when the channel is |
The |
Fixed. |
On of my users of a project that I manage that is based on SSH2 just reported the same symptoms. This is just a "+1" on this issue. Will be watching here to review. Assuming that the code changes will be published as a new "npm" distribution when ready. |
I'm the afformentioned user. I've manually applied the fix and will let you know if this is indeed the solution I needed. |
@cabarnes - Lint says you've got an unused variable here: https://github.com/smartfile/ssh2/blob/fix-disconnect/lib/protocol/SFTP.js#L2596 which came from f763271 |
@jogoldberg I did not change that file in this PR. It was a lint error that was in |
Ah. If you do
that should sort you. |
If those commands don't work, you might first need to do:
|
The tests won't run again until @mscdex runs them due to this: https://github.blog/changelog/2021-04-22-github-actions-maintainers-must-approve-first-time-contributor-workflow-runs/ |
Yes, but when he does re-run the tests, the tests will be re-run against your fork. And your fork is 5 commits behind upstream master. |
Done |
@mscdex - I can now confirm that this solved my issue. Can you please merge/release this? |
@mscdex - Just to add to the details, this solves the issue being experienced by client using OpenSSH_7.4p1 |
@mscdex - Can you please merge/release this? It is urgently needed for a production issue we're facing |
@mscdex - This is urgently needed. Can you please have a look? |
@jogoldberg I'd like to have a test for this first, I just haven't had time to write one. If @cabarnes can include one, that will help get this merged quicker. AFAIK this should be easily achievable using |
@mscdex I have added a test for this condition. It fails (hangs) without the change in this PR |
@mscdex Requesting you to kindly approve. We too are in dire need of this in production |
I should be able to take a look at it this weekend. |
@mscdex I have it skipping the integration test on Windows like the other integration tests. I don't know why the Linux tests are failing. They pass for me on my Linux system with the same version of node and OpenSSH:
|
@@ -207,6 +207,11 @@ class Session extends EventEmitter { | |||
state: 'open' | |||
} | |||
}; | |||
|
|||
this.on('eof', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might include a comment here about this being necessary to properly close the connection for some SFTP clients.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems to be addressed
@mscdex I have added the comment and the test. Let me know what you think |
Hi @mscdex - cabarnes made your requested changes a little over a week ago. Do you think you might have time to review this today? :) |
Hi @mscdex - Looks like the latest revision passed all your automated checks now. Can you please merge/release this fix? We've been operating based on a manual patching of the library now for quite some time. Thanks in advance! :) |
@@ -207,6 +207,11 @@ class Session extends EventEmitter { | |||
state: 'open' | |||
} | |||
}; | |||
|
|||
this.on('eof', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems to be addressed
@mscdex Kindly approve the pull request. We have been impacted by this in production |
The test in this PR passes for me without the runtime changes with various node versions. Is there something missing? |
@mscdex It's probably because there isn't much that I could figure out to assert on. I did manually verify that it covered the new code. I can keep looking into it. Do you have any ideas for an assertion? |
@mscdex I can't reproduce what you're seeing with node v16. The test hangs and times out when I remove the runtime changes. The test is relying on the client receiving the |
@mscdex There have been a lot of noise from the customers as we are using this library for sftp connections in production. Can you please make this available soon? |
@rk-coles I haven't had time to investigate a working test that actually fails before the change and succeeds after the change. |
Hi @mscdex : This PR has been opened for quite some time now. |
@mscdex - can we please get this merged? |
@mscdex Bumping this, any updates on the blockers? |
@mscdex - This has been waiting 6 months now. This is a 1 line code change that multiple developers have confirmed fixes a major show-stopper issue. This change is badly needed. Can you please prioritize the merge? |
@mscdex Bumping this again, we've had another client unable to close their connection as they send |
@mscdex - This PR is now waiting 1 year since the comment and test you requested were added. Can you please merge this? |
Thank you all for the amazing work! I wanted to bump this as well as I'm facing this exact issue. The only workaround I've found is to add the following to my server implementation:
But this is not safe for the long term as it requires use of the the private |
There is an open PR in the upstream / ssh2 library related to properly closing SFTP channels when a `CHANNEL_EOF` message is received[1]. Unfortunately that PR has not yet been merged. Until that happens we need to handle the signal ourselves. Unfortunately this requires us to access "private" attributes (JavaScript doesn't support the concept of private attributes, so we are able to do this...). This is, of course a terrible and horrible idea and all of our tooling gets very upset about it. As a result I had to disable the tooling for the relevant line. Once the PR is merged in upstream we should upgrade to it and delete the contents of this commit. Issue #45 rclone hangs after completion [1] mscdex/ssh2#1111
There is an open PR in the upstream / ssh2 library related to properly closing SFTP channels when a `CHANNEL_EOF` message is received[1]. Unfortunately that PR has not yet been merged. Until that happens we need to handle the signal ourselves. Unfortunately this requires us to access "private" attributes (JavaScript doesn't support the concept of private attributes, so we are able to do this...). This is, of course a terrible and horrible idea and all of our tooling gets very upset about it. As a result I had to disable the tooling for the relevant line. Once the PR is merged in upstream we should upgrade to it and delete the contents of this commit. Issue #45 rclone hangs after completion [1] mscdex/ssh2#1111
There is an open PR in the upstream / ssh2 library related to properly closing SFTP channels when a `CHANNEL_EOF` message is received[1]. Unfortunately that PR has not yet been merged. Until that happens we need to handle the signal ourselves. Unfortunately this requires us to access "private" attributes (JavaScript doesn't support the concept of private attributes, so we are able to do this...). This is, of course a terrible and horrible idea and all of our tooling gets very upset about it. As a result I had to disable the tooling for the relevant line. Once the PR is merged in upstream we should upgrade to it and delete the contents of this commit. Issue #45 rclone hangs after completion [1] mscdex/ssh2#1111
There is an open PR in the upstream / ssh2 library related to properly closing SFTP channels when a `CHANNEL_EOF` message is received[1]. Unfortunately that PR has not yet been merged. Until that happens we need to handle the signal ourselves. Unfortunately this requires us to access "private" attributes (JavaScript doesn't support the concept of private attributes, so we are able to do this...). This is, of course a terrible and horrible idea and all of our tooling gets very upset about it. As a result I had to disable the tooling for the relevant line. Once the PR is merged in upstream we should upgrade to it and delete the contents of this commit. Issue #45 rclone hangs after completion [1] mscdex/ssh2#1111
I ran into #1029 . The workaround in that issue works for most clients but fails with PuTTY scp (
pscp
). Looking into it further, it seems that these clients sendCHANNEL_EOF
whenexit
,bye
, orquit
is executed. When the server does not close the connection, the session hangs. This PR addresses the issue by handling theeof
signal and properly closing the connection. This change has been tested to work forsftp
,pscp
,WinSCP
, andparamiko
.I'm not completely sure that this is the correct place, but hopefully if it is not, it is helpful in pointing to the correct place to fix this.