mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-02 06:19:10 -07:00
Add parent pid to persistent connection socket path hash (#33518)
* Add parent pid to persistent connection socket path hash Fixes #33192 * Add parent pid in persistent connection socket path hash to avoid using same socket path for multiple simultaneous connection to same remote host. * Ensure unique persistent socket path for each ansible-playbook run * Fix CI failures
This commit is contained in:
parent
08a2338277
commit
2f932d8767
5 changed files with 17 additions and 10 deletions
|
@ -92,6 +92,8 @@ class Connection(ConnectionBase):
|
|||
self._terminal = None
|
||||
self._cliconf = None
|
||||
|
||||
self._ansible_playbook_pid = kwargs.get('ansible_playbook_pid')
|
||||
|
||||
if self._play_context.verbosity > 3:
|
||||
logging.getLogger('paramiko').setLevel(logging.DEBUG)
|
||||
|
||||
|
@ -220,7 +222,8 @@ class Connection(ConnectionBase):
|
|||
value to None and the _connected value to False
|
||||
'''
|
||||
ssh = connection_loader.get('ssh', class_only=True)
|
||||
cp = ssh._create_control_path(self._play_context.remote_addr, self._play_context.port, self._play_context.remote_user, self._play_context.connection)
|
||||
cp = ssh._create_control_path(self._play_context.remote_addr, self._play_context.port, self._play_context.remote_user, self._play_context.connection,
|
||||
self._ansible_playbook_pid)
|
||||
|
||||
tmp_path = unfrackpath(C.PERSISTENT_CONTROL_PATH_DIR)
|
||||
socket_path = unfrackpath(cp % dict(directory=tmp_path))
|
||||
|
|
|
@ -75,7 +75,7 @@ class Connection(ConnectionBase):
|
|||
Starts the persistent connection
|
||||
'''
|
||||
master, slave = pty.openpty()
|
||||
p = subprocess.Popen(["ansible-connection"], stdin=slave, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
p = subprocess.Popen(["ansible-connection", to_text(os.getppid())], stdin=slave, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdin = os.fdopen(master, 'wb', 0)
|
||||
os.close(slave)
|
||||
|
||||
|
|
|
@ -315,11 +315,13 @@ class Connection(ConnectionBase):
|
|||
return self
|
||||
|
||||
@staticmethod
|
||||
def _create_control_path(host, port, user, connection=None):
|
||||
def _create_control_path(host, port, user, connection=None, pid=None):
|
||||
'''Make a hash for the controlpath based on con attributes'''
|
||||
pstring = '%s-%s-%s' % (host, port, user)
|
||||
if connection:
|
||||
pstring += '-%s' % connection
|
||||
if pid:
|
||||
pstring += '-%s' % to_text(pid)
|
||||
m = hashlib.sha1()
|
||||
m.update(to_bytes(pstring))
|
||||
digest = m.hexdigest()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue