Netdev List
 help / color / mirror / Atom feed
From: Rishikesh Jethwani <rjethwani@purestorage.com>
To: netdev@vger.kernel.org
Cc: Rishikesh Jethwani <rjethwani@purestorage.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org
Subject: [PATCH net v2 2/3] selftests: net: py: add a bkg() timeout and kill the child when it expires
Date: Thu, 19 Nov 2026 12:13:38 -0700	[thread overview]
Message-ID: <20261119191341.4089157-2-rjethwani@purestorage.com> (raw)
In-Reply-To: <20261119191341.4089157-1-rjethwani@purestorage.com>

bkg() waits a fixed 20s for its command on exit and, on timeout, raises
with the child still running, outliving the devices and namespaces the
test tears down. Add a timeout argument for that wait, and kill the
child when it expires before raising TimeoutExpired as before.

Signed-off-by: Rishikesh Jethwani <rjethwani@purestorage.com>
---
 tools/testing/selftests/net/lib/py/utils.py | 28 ++++++++++++++++++---
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
index 1727bc418073..7a3fc39db334 100644
--- a/tools/testing/selftests/net/lib/py/utils.py
+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -104,13 +104,32 @@ class cmd:
     def _process_terminate(self, terminate, timeout):
         if terminate:
             self.proc.terminate()
-        stdout, stderr = self.proc.communicate(timeout=timeout)
+        timed_out = None
+        try:
+            stdout, stderr = self.proc.communicate(timeout=timeout)
+        except subprocess.TimeoutExpired as exc:
+            # terminate() is only a request, and bkg() with exit_wait or
+            # ksft_wait never sends one, so kill rather than leave the child
+            # running. That does not stop a command run over ssh on the
+            # remote; it needs a bound of its own.
+            self.proc.kill()
+            try:
+                stdout, stderr = self.proc.communicate(timeout=1)
+            except subprocess.TimeoutExpired:
+                # A grandchild (shell=True, ssh) still holds the pipes.
+                self.proc.wait()
+                stdout, stderr = b"", b""
+            timed_out = exc
+
         self.stdout = stdout.decode("utf-8")
         self.stderr = stderr.decode("utf-8")
         self.proc.stdout.close()
         self.proc.stderr.close()
         self.ret = self.proc.returncode
 
+        if timed_out:
+            raise timed_out
+
         return stdout, stderr
 
     def process(self, terminate=True, fail=None, expect_fail=False, timeout=20):
@@ -179,11 +198,12 @@ class bkg(cmd):
     """
     def __init__(self, comm, shell=None, fail=None, expect_fail=None,
                  ns=None, host=None, exit_wait=False, ksft_ready=None,
-                 ksft_wait=None):
+                 ksft_wait=None, timeout=20):
         super().__init__(comm, background=True,
                          shell=shell, fail=fail, expect_fail=expect_fail,
                          ns=ns, host=host, ksft_ready=ksft_ready,
-                         ksft_wait=ksft_wait)
+                         ksft_wait=ksft_wait, timeout=timeout)
+        self.timeout = timeout
         self.terminate = not exit_wait and not ksft_wait
         self._exit_wait = exit_wait
         self.check_fail = fail
@@ -203,7 +223,7 @@ class bkg(cmd):
         if self.proc.poll() is None:
             terminate = terminate or (self._exit_wait and ex_type is not None)
         return self.process(terminate=terminate, fail=self.check_fail,
-                            expect_fail=self.expect_fail)
+                            expect_fail=self.expect_fail, timeout=self.timeout)
 
 
 GLOBAL_DEFER_QUEUE = []
-- 
2.50.1


  reply	other threads:[~2026-11-19 19:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 19:13 [PATCH net v2 1/3] tls: device: keep tls_sw_fallback() from encrypting its own output Rishikesh Jethwani
2026-11-19 19:13 ` Rishikesh Jethwani [this message]
2026-11-19 19:13 ` [PATCH net v2 3/3] selftests: net: add TLS offload over bond tests Rishikesh Jethwani
2026-11-19 19:18 ` [PATCH net v2 1/3] tls: device: keep tls_sw_fallback() from encrypting its own output netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119191341.4089157-2-rjethwani@purestorage.com \
    --to=rjethwani@purestorage.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox