[stable-2.10] wait_for - ignore psutil related errors (#72401) (#72406)

When enumerating connections with psutil, catch and ignore errors to avoid returning a stack trace.

Co-authored-by:  Matt Martz <matt@sivel.net>
(cherry picked from commit fb09fd2a23)
pull/72904/head
Sam Doran 4 years ago committed by GitHub
parent c422bc64dc
commit 4e34aa0c19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- wait_for - catch and ignore errors when getting active connections with psutil (https://github.com/ansible/ansible/issues/72322)

@ -287,10 +287,14 @@ class TCPConnectionInfo(object):
def get_active_connections_count(self):
active_connections = 0
for p in psutil.process_iter():
try:
if hasattr(p, 'get_connections'):
connections = p.get_connections(kind='inet')
else:
connections = p.connections(kind='inet')
except psutil.Error:
# Process is Zombie or other error state
continue
for conn in connections:
if conn.status not in self.module.params['active_connection_states']:
continue

@ -0,0 +1,13 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
import time
child_pid = os.fork()
if child_pid > 0:
time.sleep(60)
else:
sys.exit()

@ -153,6 +153,16 @@
name: psutil
when: ansible_system != 'Linux'
- name: Copy zombie.py
copy:
src: zombie.py
dest: "{{ output_dir }}"
- name: Create zombie process
shell: "{{ ansible_python.executable }} {{ output_dir }}/zombie"
async: 90
poll: 0
- name: test wait for port drained
wait_for:
port: "{{ http_port }}"

Loading…
Cancel
Save