Commands started with ksft_wait keep the parent write end in ksft_term_fd. After communicate() reaps the child, that descriptor is still open, so each completed command leaks a pipe in the Python process. Close the parent end after successful communication and clear its saved value, before decoding output or reporting a failed child exit status. Leave paths where communication has not completed unchanged. Run this from tools/testing/selftests/net to repeat the supported pipe handshake. It prints 16 on the original helper and 0 with the fix: python3 - <<'PYCODE' import os from lib.py import bkg child = ["python3", "-c", "import os; os.write(int(os.environ['KSFT_READY_FD']), b'1');" "os.read(int(os.environ['KSFT_WAIT_FD']), 1)"] before = len(os.listdir("/proc/self/fd")) for _ in range(16): with bkg(child, ksft_wait=3): pass print(len(os.listdir("/proc/self/fd")) - before) PYCODE Found by AI-assisted inspection. Both this reproducer and a C helper using the existing ksft_ready()/ksft_wait() functions confirm the fix. Normal completion, initialization EOF and nonzero child exit each leak 16 descriptors before and none after; ordinary and ready-only controls remain clean. No kernel instrumentation or fault injection was used. No hardware suite was run. Timeout cleanup and a child exiting after readiness but before the parent's notification remain outside this fix. Fixes: 71477137994f ("selftests: drv-net: add a way to wait for a local process") Signed-off-by: Jingjing Xu --- tools/testing/selftests/net/lib/py/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py index 1727bc418073..72c5af28cc7e 100644 --- a/tools/testing/selftests/net/lib/py/utils.py +++ b/tools/testing/selftests/net/lib/py/utils.py @@ -105,6 +105,9 @@ class cmd: if terminate: self.proc.terminate() stdout, stderr = self.proc.communicate(timeout=timeout) + if self.ksft_term_fd is not None: + os.close(self.ksft_term_fd) + self.ksft_term_fd = None self.stdout = stdout.decode("utf-8") self.stderr = stderr.decode("utf-8") self.proc.stdout.close() base-commit: 2208ab00f4f213ade91ab775e7f8c4dacdcc856e -- 2.53.0