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

fix:Before killing a process under high concurrency, it is necessary … #2261

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion paramiko/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def recv(self, size):
raise ProxyCommandFailure(" ".join(self.cmd), e.strerror)

def close(self):
os.kill(self.process.pid, signal.SIGTERM)
# The subprocess may be killed in other ways (For example, asynchronous)
# Before killing this subprocess, you need to determine whether it exists
if not self.closed:
os.kill(self.process.pid, signal.SIGTERM)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your guidance.

Copy link
Contributor

Choose a reason for hiding this comment

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

@nuonuonn Thanks for the explain.

The issue has been fixed in Python 3.10.0, python/cpython@01a202a

However, the issue occurs for the version or early. We could change like the following:

diff --git a/paramiko/proxy.py b/paramiko/proxy.py
index f7609c984..111e91627 100644
--- a/paramiko/proxy.py
+++ b/paramiko/proxy.py
@@ -119,7 +119,13 @@ class ProxyCommand(ClosingContextManager):
             raise ProxyCommandFailure(" ".join(self.cmd), e.strerror)

     def close(self):
-        os.kill(self.process.pid, signal.SIGTERM)
+        try:
+            self.process.terminate()
+        except ProcessLookupError:
+            pass  # Suppress the error if the process is not existent
+        # Close pipes and avoid zombie process
+        with self.process:
+            pass

     @property
     def closed(self):


@property
def closed(self):
Expand Down