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
how to Kill remote process on channel.close so it can be garbage collected correctly? #785
Comments
|
There is a signal send message in the SSH protocol RFC https://www.ietf.org/rfc/rfc4254.txt that looks like it would be exactly what you seek. Even though I don't see direct support in paramiko for this category of messages, you should be able to construct it in a Message and use transport._send_user_message() to issue SIGTERM and/or SIGKILL to the underlying channel. I may try my hand at putting together a PR for a general Channel.send_signal(), but not sure when I'd be able to dabble with it. |
|
Got something ready to go, except for the fact that during testing, it turns out that OpenSSH server doesn't do anything with the signal request (other than logging that it received it). Seems like they've been perpetually kicking that feature request out to next release for quite some time. |
|
Thanks for fielding this, @radssh! Agree with your analysis, at a glance. @rustyscottweber Another option I can think of offhand is for you to wrap your remote processes in Going to close this as "cantfix" for now but as always, more discussion is totally cool. Thanks for the report! |
|
I've got three semi-related feature bits coded:
Let me know if you're okay with all this lumped into one PR, or if you prefer them split up, especially if there's a bunch of tinkering to do on the last part. |
|
I think one PR is probably OK, having any of those things merged without the other doesn't feel crazy useful & I'd feel compelled to track/merge/release them together anyways. Thanks! |
|
Looks like OpenSSH code is prepping this for an upcoming release (at long last) |
|
Thank you for the update @radssh. It will probably be years before every outdated ssh server which just logs a message is phased out, but it's good progress and news. Thank you for putting in features as well. |
|
Did this actually make its way into paramiko? |
I have a problem where getting the PTY is not an option I would/can consider. However, I need to be able to kill a long running process when the process is no longer needed. Previously, this could be accompolished by setting get_pty=True.. But that's not an option for me because of certain new issues with wall spitting out lots of data which will tamper with my long running output.
I have some code similar to this..
pstdin, pstdout, pstderr = connection.pclient.exec_command(command=cmd, timeout=timeout, get_pty=False)
do stuff for a really long time
self.pstdout.channel.close()
I also cannot call kill on the process using the command line or the 'kill -9' or 'pkill' because there are MANY other processes that look exactly like it and I cannot distinguish which process is the one that needs to die and which ones need to keep living.. Strange.. I know....
Is there a way to get the remote ssh server to kill the process when the channel is closed without using get_pty=True, or is it just a better solution to create a new connection for each process and then disconnect the connection to make the ssh server clean up the process that way to ensure that there are no zombie processes created?
The text was updated successfully, but these errors were encountered: