Netdev List
 help / color / mirror / Atom feed
From: Allison Henderson <achender@kernel.org>
To: netdev@vger.kernel.org, pabeni@redhat.com, edumazet@google.com,
	kuba@kernel.org, horms@kernel.org, linux-rdma@vger.kernel.org,
	achender@kernel.org, linux-kselftest@vger.kernel.org,
	shuah@kernel.org
Subject: [PATCH net-next v3 08/11] selftests: rds: Handle errors in netns_socket
Date: Sun, 17 May 2026 18:24:40 -0700	[thread overview]
Message-ID: <20260518012443.2629206-9-achender@kernel.org> (raw)
In-Reply-To: <20260518012443.2629206-1-achender@kernel.org>

Sockets created by child processes in netns_socket may raise
exceptions that are currently not handled by the parent.  If for
example a namespace didn't exist or the rds module didn't load. Because
these exceptions occur with in a child thread, the child thread exits,
but the parent does not check the return status.

Further, allowing the child processes to quietly raise exceptions
will cause problems later if the parent registers clean up functions
with atexit.  Since the child processes inherit the parents handlers,
they may prematurely call the parents cleanup routines without the
parent being aware.

Fix this by all catching exceptions raised by the child processes.
Child errors surface as a non-zero exit status, which are then
properly raised in the parent process.

Signed-off-by: Allison Henderson <achender@kernel.org>
---
 tools/testing/selftests/net/rds/test.py | 27 +++++++++++++------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/tools/testing/selftests/net/rds/test.py b/tools/testing/selftests/net/rds/test.py
index f7d0dba85131e..2188221ee7805 100755
--- a/tools/testing/selftests/net/rds/test.py
+++ b/tools/testing/selftests/net/rds/test.py
@@ -56,27 +56,28 @@ def netns_socket(netns, *sock_args):
 
     child = os.fork()
     if child == 0:
-        # change network namespace
-        with open(f'/var/run/netns/{netns}', encoding='utf-8') as f:
-            try:
+        try:
+            # change network namespace
+            with open(f'/var/run/netns/{netns}', encoding='utf-8') as f:
                 setns(f.fileno(), 0)
-            except IOError as e:
-                print(e.errno)
-                print(e)
-
-        # create socket in target namespace
-        sock = socket.socket(*sock_args)
+            # create socket in target namespace
+            sock = socket.socket(*sock_args)
 
-        # send resulting socket to parent
-        socket.send_fds(u0, [], [sock.fileno()])
+            # send resulting socket to parent
+            socket.send_fds(u0, [], [sock.fileno()])
 
-        os._exit(0)
+            os._exit(0)
+        except BaseException:
+            os._exit(1)
 
     # receive socket from child
     _, fds, _, _ = socket.recv_fds(u1, 0, 1)
-    os.waitpid(child, 0)
+    _, status = os.waitpid(child, 0)
     u0.close()
     u1.close()
+    if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0:
+        raise RuntimeError(
+            f"netns_socket child failed in netns {netns} (status={status})")
     return socket.fromfd(fds[0], *sock_args)
 
 def send_burst(socks, ip_addrs, snd_hashes, nr_sent, nr_total):
-- 
2.25.1


  parent reply	other threads:[~2026-05-18  1:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-18  1:24 [PATCH net-next v3 00/11] selftests: rds: Add ROCE support to rds selftests Allison Henderson
2026-05-18  1:24 ` [PATCH net-next v3 01/11] net/rds: Don't sleep inside rds_ib_conn_path_shutdown Allison Henderson
2026-05-18  1:24 ` [PATCH net-next v3 02/11] selftests: rds: Add helper function setup_tcp() in test.py Allison Henderson
2026-05-18  1:24 ` [PATCH net-next v3 03/11] selftests: rds: Add helper function check_info() " Allison Henderson
2026-05-18  1:24 ` [PATCH net-next v3 04/11] selftests: rds: Add helper function send_burst() " Allison Henderson
2026-05-18  1:24 ` [PATCH net-next v3 05/11] selftests: rds: Add helper function recv_burst() " Allison Henderson
2026-05-18  1:24 ` [PATCH net-next v3 06/11] selftests: rds: Add helper function verify_hashes() " Allison Henderson
2026-05-18  1:24 ` [PATCH net-next v3 07/11] selftests: rds: Add helper function snd_rcv_packets() " Allison Henderson
2026-05-18  1:24 ` Allison Henderson [this message]
2026-05-18  1:24 ` [PATCH net-next v3 09/11] selftests: rds: Register network teardown via atexit Allison Henderson
2026-05-18  1:24 ` [PATCH net-next v3 10/11] selftests: rds: Add ROCE support to test.py Allison Henderson
2026-05-18  1:24 ` [PATCH net-next v3 11/11] selftests: rds: Add ROCE support to run.sh Allison Henderson

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=20260518012443.2629206-9-achender@kernel.org \
    --to=achender@kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-rdma@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