misc fixes for sockopt selftests
Subsystems (3)
Geliang Tang
reviewerv2 cover misc fixes for sockopt selftests
v2:
- patch 2: we should address this resource leak by adding the missing close() calls on the server side, rather than by removing the correct existing ones on the client side.
- patch 3: fix more error messages as Matt suggested.
This patch series addresses several resource management issues in the MPTCP sockopt selftests.
Geliang Tang (3):
selftests: mptcp: close server file descriptor
selftests: mptcp: close IPC descriptor on server side
selftests: mptcp: sockopt: fix error messages
tools/testing/selftests/net/mptcp/mptcp_inq.c | 2 ++ .../selftests/net/mptcp/mptcp_sockopt.c | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-)
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH v2 1/3 selftests: mptcp: close server file descriptor
From: Geliang Tang <[email protected]>
The server file descriptor ('fd') is opened in server() but never closed. While accepted connections are properly closed in process_one_client(), the main listening socket remains open, causing a resource leak.
This patch ensures the server fd is properly closed after processing clients, bringing the sockopt and inq test cases in line with proper resource cleanup practices.
--- tools/testing/selftests/net/mptcp/mptcp_inq.c | 1 + tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 1 + 2 files changed, 2 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_inq.c +1 -0
@@ -502,6 +502,7 @@ static int server(int unixfd)process_one_client (r, unixfd); +close (fd);return 0 ; }
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +1 -0
@@ -722,6 +722,7 @@ static int server(int pipefd)process_one_client (r, pipefd); +close (fd);return 0 ; }
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH v2 2/3 selftests: mptcp: close IPC descriptor on server side
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The client-side function 'connect_one_server()' correctly closes the IPC descriptor (a pipe or UNIX socket) after use. However, the server-side functions 'process_one_client()' in both 'mptcp_sockopt.c' and 'mptcp_inq.c' were missing the corresponding 'close()' call for their IPC descriptors.
This omission could lead to resource leaks (file descriptors) in the test server processes over time.
This patch adds the missing 'close(pipefd)' and 'close(unixfd)' calls in the server-side code, ensuring symmetric and correct resource cleanup.
--- tools/testing/selftests/net/mptcp/mptcp_inq.c | 1 + tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 1 + 2 files changed, 2 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_inq.c +1 -0
@@ -462,6 +462,7 @@ static void process_one_client(int fd, int unixfd)get_tcp_inq (&msg, &tcp_inq);assert (tcp_inq ==1 ); +close (unixfd);close (fd); }
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +1 -0
@@ -685,6 +685,7 @@ static void process_one_client(int fd, int pipefd) s.last_sample.mptcpi_bytes_acked - ret2); } +close (pipefd);close (fd); }
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH v2 3/3 selftests: mptcp: sockopt: fix error messages
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch fixes several issues in the error reporting of the MPTCP sockopt selftest:
1. Add diff calculation: The error messages for counter mismatches now include the actual difference ('diff') between the expected and received values, making debugging significantly easier.
2. Fix variable usage: The error check for 'mptcpi_bytes_acked' incorrectly used 'ret2' (sent bytes) for both the expected value and the difference calculation. It now correctly uses 'ret' (received bytes), which is the expected value for bytes_acked.
3. Fix off-by-one in diff: The calculation for the 'mptcpi_rcv_delta' diff was 's.mptcpi_rcv_delta - ret', which is off-by-one. It has been corrected to 's.mptcpi_rcv_delta - (ret + 1)' to match the expected value in the condition above it.
--- .../testing/selftests/net/mptcp/mptcp_sockopt.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +10 -6
@@ -667,22 +667,26 @@ static void process_one_client(int fd, int pipefd)do_getsockopts (&s, fd, ret, ret2);if (s.mptcpi_rcv_delta != (uint64_t )ret +1 ) -xerror ("mptcpi_rcv_delta %" PRIu64", expect %" PRIu64, s.mptcpi_rcv_delta, ret +1 , s.mptcpi_rcv_delta - ret); +xerror ("mptcpi_rcv_delta %" PRIu64", expect %" PRIu64", diff %" PRId64, + s.mptcpi_rcv_delta, ret +1 , s.mptcpi_rcv_delta - (ret +1 ));/* be nice when running on top of older kernel */ if (s.pkt_stats_avail) {if (s.last_sample.mptcpi_bytes_sent != ret2) -xerror ("mptcpi_bytes_sent %" PRIu64", expect %" PRIu64, +xerror ("mptcpi_bytes_sent %" PRIu64", expect %" PRIu64 +", diff %" PRId64, s.last_sample.mptcpi_bytes_sent, ret2, s.last_sample.mptcpi_bytes_sent - ret2);if (s.last_sample.mptcpi_bytes_received != ret) -xerror ("mptcpi_bytes_received %" PRIu64", expect %" PRIu64, +xerror ("mptcpi_bytes_received %" PRIu64", expect %" PRIu64 +", diff %" PRId64, s.last_sample.mptcpi_bytes_received, ret, s.last_sample.mptcpi_bytes_received - ret);if (s.last_sample.mptcpi_bytes_acked != ret) -xerror ("mptcpi_bytes_acked %" PRIu64", expect %" PRIu64, - s.last_sample.mptcpi_bytes_acked, ret2, - s.last_sample.mptcpi_bytes_acked - ret2); +xerror ("mptcpi_bytes_acked %" PRIu64", expect %" PRIu64 +", diff %" PRId64, + s.last_sample.mptcpi_bytes_acked, ret, + s.last_sample.mptcpi_bytes_acked - ret); }close (pipefd);
Signature · 1 line
2.48.1
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Unstable: 1 failed test(s): packetdrill_dss 🔴
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/17423040759
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/c5af9373827e
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=998230
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 2/3] selftests: mptcp: close IPC descriptor on server side
In reply to Geliang TangHi Geliang,
Quoted 7 lines · Geliang Tang
From: Geliang Tang <[email protected]>
The client-side function '
connect_one_server()' correctly closes the IPC descriptor (a pipe or UNIX socket) after use. However, the server-side functions 'process_one_client()' in both 'mptcp_sockopt.c' and 'mptcp_inq.c' were missing the corresponding 'close()' call for their IPC descriptors.
Quoted 5 lines
This omission could lead to resource leaks (file descriptors) in the test server processes over time.
This patch adds the missing 'close(pipefd)' and 'close(unixfd)' calls in the server-side code, ensuring symmetric and correct resource cleanup.
I don't know if we need such patch. I mean: yes, that's better to close such FD before closing the application, but then:
- it is strange to close it in the middle of a function (process_one_client()), and not where it has been created (main())
- if I'm not mistaken, unixfds[0] / pipefds[0] are not closed in the server process.
So if you really want to fix that, I think it would be better to close all these unix FD in the 'main()' function, no?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 2/3] selftests: mptcp: close IPC descriptor on server side
Hi Geliang,
Quoted 8 lines · Matthieu Baerts
Hi Geliang,
Quoted 5 lines · Geliang Tang
From: Geliang Tang <[email protected]>
The client-side function '
connect_one_server()' correctly closes the IPC descriptor (a pipe or UNIX socket) after use. However, the server-side functions 'process_one_client()' in both 'mptcp_sockopt.c' and 'mptcp_inq.c'
FYI, checkpatch is complaining that this line is too long.
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/17423040753
Because it is not an output of a log, can you go to the next line after max 72 chars please?
(I didn't check, but there are other similar errors reported by checkpatch. *If they make sense*, don't hesitate to fix them as well)
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 3/3] selftests: mptcp: sockopt: fix error messages
In reply to Geliang TangHi Geliang,
Quoted 8 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch fixes several issues in the error reporting of the MPTCP sockopt selftest:
1. Add diff calculation: The error messages for counter mismatches now include the actual difference ('diff') between the expected and received values, making debugging significantly easier.
This could be interpreted as a new feature while it is a fix. What about:
Fix diff not printed: The error messages for counter mismatches had the actual difference ('diff') as argument, but it was missing in the format string. Displaying it makes the debugging easier.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerRe: [PATCH mptcp-net v2 2/3] selftests: mptcp: close IPC descriptor on server side
In reply to Matthieu BaertsHi Matt,
Quoted 22 lines · Matthieu Baerts
Hi Geliang,
Quoted 11 lines · Geliang Tang
From: Geliang Tang <[email protected]>
The client-side function '
connect_one_server()' correctly closes the IPC
descriptor (a pipe or UNIX socket) after use. However, the server- side
functions 'process_one_client()' in both 'mptcp_sockopt.c' and 'mptcp_inq.c'
were missing the corresponding 'close()' call for their IPC descriptors.Quoted 7 lines
This omission could lead to resource leaks (file descriptors) in the test
server processes over time.This patch adds the missing 'close(pipefd)' and 'close(unixfd)' calls in the
server-side code, ensuring symmetric and correct resource cleanup.
Quoted 7 lines
I don't know if we need such patch. I mean: yes, that's better to close
such FD before closing the application, but then:- it is strange to close it in the middle of a function (
process_one_client()), and not where it has been created (main())
Yes, close it in main() is much better. I added close(pipefds[1]) after calling server(pipefds[1]) in the new version instead of adding close(pipefd) in process_one_client().
Quoted 2 lines
- if I'm not mistaken, unixfds[0] / pipefds[0] are not closed in the server process.
Yes, indeed. close(pipefds[0]) is missing in the server process too.
Quoted 3 lines
So if you really want to fix that, I think it would be better to close
all these unix FD in the 'main()' function, no?
I also moved 'close(pipefd)' from connect_one_server() to main(), just after calling client(pipefds[0]). And here's the new version:
e1 = pipe(pipefds);
if (e1 < 0)
die_perror("pipe");
s = xfork();
if (s == 0) {
close(pipefds[0]);
ret = server(pipefds[1]);
close(pipefds[1]);
return ret;
}
close(pipefds[1]);
/* wait until server bound a socket */
e1 = read(pipefds[0], &e1, 4);
assert(e1 == 4);
c = xfork();
if (c == 0) {
ret = client(pipefds[0]);
close(pipefds[0]);
return ret;
}
close(pipefds[0]);Is this better?
Thanks,
-Geliang
Quoted 3 lines
Cheers,
Matt
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 2/3] selftests: mptcp: close IPC descriptor on server side
Hi Geliang,
Quoted 76 lines · Geliang Tang
Hi Matt,
Quoted 22 lines · Matthieu Baerts
Hi Geliang,
Quoted 11 lines · Geliang Tang
From: Geliang Tang <[email protected]>
The client-side function '
connect_one_server()' correctly closes the IPC
descriptor (a pipe or UNIX socket) after use. However, the server- side
functions 'process_one_client()' in both 'mptcp_sockopt.c' and 'mptcp_inq.c'
were missing the corresponding 'close()' call for their IPC descriptors.Quoted 7 lines
This omission could lead to resource leaks (file descriptors) in the test
server processes over time.This patch adds the missing 'close(pipefd)' and 'close(unixfd)' calls in the
server-side code, ensuring symmetric and correct resource cleanup.Quoted 7 lines
I don't know if we need such patch. I mean: yes, that's better to close
such FD before closing the application, but then:- it is strange to close it in the middle of a function (
process_one_client()), and not where it has been created (main())Yes, close it in
main()is much better. I addedclose(pipefds[1])after callingserver(pipefds[1])in the new version instead of adding close(pipefd) inprocess_one_client().Quoted 2 lines
- if I'm not mistaken, unixfds[0] / pipefds[0] are not closed in the server process.
Yes, indeed.
close(pipefds[0])is missing in the server process too.Quoted 3 lines
So if you really want to fix that, I think it would be better to close
all these unix FD in the 'main()' function, no?I also moved 'close(pipefd)' from
connect_one_server()tomain(), just after callingclient(pipefds[0]). And here's the new version:e1 = pipe(pipefds); if (e1 < 0) die_perror("pipe"); s = xfork(); if (s == 0) { close(pipefds[0]); ret = server(pipefds[1]); close(pipefds[1]); return ret; } close(pipefds[1]); /* wait until server bound a socket */ e1 = read(pipefds[0], &e1, 4); assert(e1 == 4); c = xfork(); if (c == 0) { ret = client(pipefds[0]); close(pipefds[0]); return ret; } close(pipefds[0]);
Quoted 1 line
Is this better?
(sorry, I thought I replied...)
Yes, that looks more manageable like that: all close() by the "function owner" (where they have been opened).
Also, please don't bother about closing all FD in the error exit paths, e.g. in xfork(), etc. when xerror() is called. These are more unexpected errors, and closing everything properly is this case, for the selftests is not a priority, and might cause issues if the code is more complex (+ issues for the backports, etc.)
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerRe: [PATCH mptcp-net v2 2/3] selftests: mptcp: close IPC descriptor on server side
Hi Matt,
Quoted 96 lines · Matthieu Baerts
Hi Geliang,
Quoted 83 lines · Geliang Tang
Hi Matt,
Quoted 26 lines · Matthieu Baerts
Hi Geliang,
Quoted 18 lines · Geliang Tang
From: Geliang Tang <[email protected]>
The client-side function '
connect_one_server()' correctly closes
the IPC
descriptor (a pipe or UNIX socket) after use. However, the server-
side
functions 'process_one_client()' in both 'mptcp_sockopt.c' and 'mptcp_inq.c'
were missing the corresponding 'close()' call for their IPC descriptors.This omission could lead to resource leaks (file descriptors) in
the test
server processes over time.Quoted 4 lines
This patch adds the missing 'close(pipefd)' and 'close(unixfd)' calls in the
server-side code, ensuring symmetric and correct resource cleanup.Quoted 8 lines
I don't know if we need such patch. I mean: yes, that's better to close
such FD before closing the application, but then:- it is strange to close it in the middle of a function (
process_one_client()), and not where it has been created (main())Yes, close it in
main()is much better. I addedclose(pipefds[1])after
callingserver(pipefds[1])in the new version instead of adding close(pipefd) inprocess_one_client().Quoted 3 lines
- if I'm not mistaken, unixfds[0] / pipefds[0] are not closed in the
server process.Yes, indeed.
close(pipefds[0])is missing in the server process too.Quoted 3 lines
So if you really want to fix that, I think it would be better to close
all these unix FD in the 'main()' function, no?I also moved 'close(pipefd)' from
connect_one_server()tomain(), just
after callingclient(pipefds[0]). And here's the new version:e1 = pipe(pipefds);
if (e1 < 0)
die_perror("pipe");s =
xfork();
if (s == 0) {
close(pipefds[0]);
ret =server(pipefds[1]);
close(pipefds[1]);
return ret;
}
close(pipefds[1]);/* wait until server bound a socket */
e1 =read(pipefds[0], &e1, 4);
assert(e1 == 4);c =
xfork();
if (c == 0) {
ret =client(pipefds[0]);
close(pipefds[0]);
return ret;
}Quoted 3 lines
close(pipefds[0]);Is this better?
(sorry, I thought I replied...)
Yes, that looks more manageable like that: all
close()by the "function
owner" (where they have been opened).
Quoted 9 lines
Also, please don't bother about closing all FD in the error exit paths,
e.g. inxfork(), etc. whenxerror()is called. These are more unexpected
errors, and closing everything properly is this case, for the selftests
is not a priority, and might cause issues if the code is more complex (+
issues for the backports, etc.)
I agree, the priority is really low. I think there is no need to backport these three patches. Should I change them to -next from -net in v3 and treat them as cleanups instead of fixes?
Thanks,
-Geliang
Quoted 3 lines
Cheers,
Matt
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 2/3] selftests: mptcp: close IPC descriptor on server side
Hi Geliang,
Quoted 109 lines · Geliang Tang
Hi Matt,
Quoted 96 lines · Matthieu Baerts
Hi Geliang,
Quoted 83 lines · Geliang Tang
Hi Matt,
Quoted 26 lines · Matthieu Baerts
Hi Geliang,
Quoted 18 lines · Geliang Tang
From: Geliang Tang <[email protected]>
The client-side function '
connect_one_server()' correctly closes
the IPC
descriptor (a pipe or UNIX socket) after use. However, the server-
side
functions 'process_one_client()' in both 'mptcp_sockopt.c' and 'mptcp_inq.c'
were missing the corresponding 'close()' call for their IPC descriptors.This omission could lead to resource leaks (file descriptors) in
the test
server processes over time.Quoted 4 lines
This patch adds the missing 'close(pipefd)' and 'close(unixfd)' calls in the
server-side code, ensuring symmetric and correct resource cleanup.Quoted 8 lines
I don't know if we need such patch. I mean: yes, that's better to close
such FD before closing the application, but then:- it is strange to close it in the middle of a function (
process_one_client()), and not where it has been created (main())Yes, close it in
main()is much better. I addedclose(pipefds[1])after
callingserver(pipefds[1])in the new version instead of adding close(pipefd) inprocess_one_client().Quoted 3 lines
- if I'm not mistaken, unixfds[0] / pipefds[0] are not closed in the
server process.Yes, indeed.
close(pipefds[0])is missing in the server process too.Quoted 3 lines
So if you really want to fix that, I think it would be better to close
all these unix FD in the 'main()' function, no?I also moved 'close(pipefd)' from
connect_one_server()tomain(), just
after callingclient(pipefds[0]). And here's the new version:e1 = pipe(pipefds);
if (e1 < 0)
die_perror("pipe");s =
xfork();
if (s == 0) {
close(pipefds[0]);
ret =server(pipefds[1]);
close(pipefds[1]);
return ret;
}
close(pipefds[1]);/* wait until server bound a socket */
e1 =read(pipefds[0], &e1, 4);
assert(e1 == 4);c =
xfork();
if (c == 0) {
ret =client(pipefds[0]);
close(pipefds[0]);
return ret;
}Quoted 3 lines
close(pipefds[0]);Is this better?
(sorry, I thought I replied...)
Yes, that looks more manageable like that: all
close()by the "function
owner" (where they have been opened).Quoted 9 lines
Also, please don't bother about closing all FD in the error exit paths,
e.g. inxfork(), etc. whenxerror()is called. These are more unexpected
errors, and closing everything properly is this case, for the selftests
is not a priority, and might cause issues if the code is more complex (+
issues for the backports, etc.)
Quoted 3 lines
I agree, the priority is really low. I think there is no need to backport these three patches. Should I change them to -next from -net in v3 and treat them as cleanups instead of fixes?
Good point. For the selftests, if the problems you identified are not causing issues or confusions, probably best not to target net then.
So here, if fd's should have been closed just before exiting, that's fine, no real harm. We would have backported a patch if fd were reused but not closed, or many connections were created one after the other, but not closed, etc. → there the impact could be visible.
For the 3rd patch, it is different, it might be interesting to backport it if error messages are wrong or confusing.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.