Skip to content

Fix zombie process accumulation in ProxyCommand - #962

Open
nbartos wants to merge 1 commit into
paramiko:mainfrom
nbartos:zombie
Open

nbartos wants to merge 1 commit into
paramiko:mainfrom
nbartos:zombie

Conversation

@nbartos

@nbartos nbartos commented May 17, 2017

Copy link
Copy Markdown

After a proxy command exits, a defunct process will stick around
until the calling process exits. This can accumulate to hundreds
or thousands of processes if you are polling a remote server.

This simple fix will cleanup the zombie after it's killed.

@ploxiln

ploxiln commented May 17, 2017

Copy link
Copy Markdown
Contributor

You should still send SIGTERM first, and give it a couple of seconds to exit gracefully.

@ploxiln

ploxiln commented May 17, 2017

Copy link
Copy Markdown
Contributor

(to clarify, the fix is the .wait(), thanks for identifying that problem)

@nbartos

nbartos commented May 17, 2017

Copy link
Copy Markdown
Author

The latest changeset should do what you want. It's a bit more code than I wanted it to be, because it doesn't look like python has a proper function to handle a standard TERM/wait/KILL.

Comment thread paramiko/proxy.py Outdated
self.process.terminate()
while datetime.datetime.utcnow() < kill_after:
self.process.poll()
if self.process.returncode is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this can be slightly consolidated into

if self.process.poll() is not None:

(because .poll() returns returncode)

@ploxiln

ploxiln commented May 17, 2017

Copy link
Copy Markdown
Contributor

That is what I had in mind, thanks!

@nbartos

nbartos commented May 17, 2017

Copy link
Copy Markdown
Author

Should be good now.

@ploxiln

ploxiln commented May 18, 2017

Copy link
Copy Markdown
Contributor

👍 from me

(the test failure appears to be a spurious pypy lockup in an unrelated test)

@nbartos

nbartos commented May 22, 2017

Copy link
Copy Markdown
Author

@bitprophet Any chance I could get a merge on this?

@bitprophet bitprophet added this to the Next bugfix milestone Jun 13, 2017
@bitprophet

Copy link
Copy Markdown
Member

Rebase against 2.0 and I'll consider it! (same as the other PR :)) thanks!

@nbartos

nbartos commented Jun 13, 2017

Copy link
Copy Markdown
Author

I've rebased this one against master, and created a backport for the 2.0 branch here: #996

@bitprophet

Copy link
Copy Markdown
Member

Shouldn't need two PRs for this unless I'm missing something obvious; typically we merge to 2.0 and then just merge up to 2.1, 2.2, ..., master.

@nbartos

nbartos commented Jun 14, 2017

Copy link
Copy Markdown
Author

Oh sorry, I'm just used to the master = mainline and everything is backported. I'll close the other one and move this to 2.0.

@nbartos
nbartos changed the base branch from 2.0 to master May 27, 2018 05:19
After a proxy command exits, a defunct process will stick around
until the calling process exits.  This can accumulate to hundreds
or thousands of processes if you are polling a remote server.

The main problem is that wait() wasn't being called, however some
extra logic was added to send a KILL if for some reason TERM doesn't
end up doing it.
@pvicente

Copy link
Copy Markdown

Hi, any plan of merging it into master and backport it to version 2?

@tramontano

Copy link
Copy Markdown

This is a pretty old PR, but in case anyone in the future sees this message, for my case (Win11, Python 3.12, Paramiko 3.5.0) the combination of this #962 and JulianEberius@bb1f795

Solved two issues:

  1. Proxy on windows
  2. Access Denied received upon socket closure

Hopefully this gets merged to a future release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants