[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)
This commit is contained in:
Sam Doran 2020-12-07 18:33:34 -05:00 committed by GitHub
parent c422bc64dc
commit 4e34aa0c19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 4 deletions

View file

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

View file

@ -287,10 +287,14 @@ class TCPConnectionInfo(object):
def get_active_connections_count(self):
active_connections = 0
for p in psutil.process_iter():
if hasattr(p, 'get_connections'):
connections = p.get_connections(kind='inet')
else:
connections = p.connections(kind='inet')
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

View file

@ -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()

View file

@ -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 }}"