In case of poll timeout, it might be too late to print the stats after
the socket closure.
Now, in case of poll timeout, 'ss' and 'nstat' are invoked from
mptcp_connect to print the stats before exiting. This should help
debugging poll timeout issues.
Note: for this "workaround", system() is used for debugging purposes
only. The returned result can then be safely ignored, hence the (void)!
to avoid unused-result warnings.
Also, 'nstat *Tcp*' will print '#kernel' at the top, but that's OK, and
it seems better to avoid using a pipe here.
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Changes in v3:
- use double quotes instead of single ones (Sashiko)
- Link to v2: https://patch.msgid.link/20260814-sft-mptcp-stats-b4-close-v2-1-b7a8ab3ddae8@kernel.org
Changes in v2:
- use 'ip netns identify' to avoid a warning from AI reviews
- use 'nstat -s *Tcp*' instead of using grep
- add a note about (void)!
- Link to v1: https://patch.msgid.link/20260814-sft-mptcp-stats-b4-close-v1-1-2945a591be7e@kernel.org
---
tools/testing/selftests/net/mptcp/mptcp_connect.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index ea4cb6c1bd5e..d6c2237bdba0 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -210,6 +210,19 @@ static void xgetaddrinfo(const char *node, const char *service,
}
}
+static void print_err_stats(void)
+{
+ char cmd[128];
+
+ snprintf(cmd, sizeof(cmd), "ss -Menitam -o '%cport = :%s' >&2",
+ listen_mode ? 's' : 'd', cfg_port);
+
+ fprintf(stderr, "socket stats before socket closure:\n");
+ (void)!system(cmd);
+ (void)!system("NSTAT_HISTORY=\"/tmp/$(ip netns identify).nstat\" "
+ "nstat -s '*Tcp*' >&2");
+}
+
static void set_rcvbuf(int fd, unsigned int size)
{
int err;
@@ -656,6 +669,7 @@ static int copyfd_io_poll(int infd, int peerfd, int outfd,
fprintf(stderr, "%s: poll timed out (events: "
"POLLIN %u, POLLOUT %u)\n", __func__,
fds.events & POLLIN, fds.events & POLLOUT);
+ print_err_stats();
return 2;
}
@@ -1194,6 +1208,7 @@ int main_loop_s(int listensock)
return 1;
case 0:
fprintf(stderr, "%s: timed out\n", __func__);
+ print_err_stats();
close(listensock);
return 2;
}
---
base-commit: d536472a82d18356d323227213acb5603bb9050c
change-id: 20260814-sft-mptcp-stats-b4-close-20964ff6a6ba
Best regards,
--
Matthieu Baerts (NGI0) <matttbe@kernel.org>
Hi Matt,
On Sat, 2026-08-15 at 00:28 +0200, Matthieu Baerts (NGI0) wrote:
> In case of poll timeout, it might be too late to print the stats
> after
> the socket closure.
>
> Now, in case of poll timeout, 'ss' and 'nstat' are invoked from
> mptcp_connect to print the stats before exiting. This should help
> debugging poll timeout issues.
>
> Note: for this "workaround", system() is used for debugging purposes
This print_err_stats() implementation is basically the same as
mptcp_lib_pr_err_stats() in the shell, right?
I think it's better to use mptcp_lib_pr_err_stats() in the shell to
print the information. In mptcp_connect.c, when a poll timeout occurs,
we send a signal to the shell and don't close the socket immediately -
we wait for the shell to finish printing the information before closing
it. What do you think of this approach? There's a reference
implementation in the attachment, but I haven't tested it.
Thanks,
-Geliang
> only. The returned result can then be safely ignored, hence the
> (void)!
> to avoid unused-result warnings.
>
> Also, 'nstat *Tcp*' will print '#kernel' at the top, but that's OK,
> and
> it seems better to avoid using a pipe here.
>
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> ---
> Changes in v3:
> - use double quotes instead of single ones (Sashiko)
> - Link to v2:
> https://patch.msgid.link/20260814-sft-mptcp-stats-b4-close-v2-1-b7a8ab3ddae8@kernel.org
>
> Changes in v2:
> - use 'ip netns identify' to avoid a warning from AI reviews
> - use 'nstat -s *Tcp*' instead of using grep
> - add a note about (void)!
> - Link to v1:
> https://patch.msgid.link/20260814-sft-mptcp-stats-b4-close-v1-1-2945a591be7e@kernel.org
> ---
> tools/testing/selftests/net/mptcp/mptcp_connect.c | 15
> +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c
> b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> index ea4cb6c1bd5e..d6c2237bdba0 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
> +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> @@ -210,6 +210,19 @@ static void xgetaddrinfo(const char *node, const
> char *service,
> }
> }
>
> +static void print_err_stats(void)
> +{
> + char cmd[128];
> +
> + snprintf(cmd, sizeof(cmd), "ss -Menitam -o '%cport = :%s'
> >&2",
> + listen_mode ? 's' : 'd', cfg_port);
> +
> + fprintf(stderr, "socket stats before socket closure:\n");
> + (void)!system(cmd);
> + (void)!system("NSTAT_HISTORY=\"/tmp/$(ip netns
> identify).nstat\" "
> + "nstat -s '*Tcp*' >&2");
> +}
> +
> static void set_rcvbuf(int fd, unsigned int size)
> {
> int err;
> @@ -656,6 +669,7 @@ static int copyfd_io_poll(int infd, int peerfd,
> int outfd,
> fprintf(stderr, "%s: poll timed out (events:
> "
> "POLLIN %u, POLLOUT %u)\n",
> __func__,
> fds.events & POLLIN, fds.events &
> POLLOUT);
> + print_err_stats();
> return 2;
> }
>
> @@ -1194,6 +1208,7 @@ int main_loop_s(int listensock)
> return 1;
> case 0:
> fprintf(stderr, "%s: timed out\n", __func__);
> + print_err_stats();
> close(listensock);
> return 2;
> }
>
> ---
> base-commit: d536472a82d18356d323227213acb5603bb9050c
> change-id: 20260814-sft-mptcp-stats-b4-close-20964ff6a6ba
>
> Best regards,
> --
> Matthieu Baerts (NGI0) <matttbe@kernel.org>
>
Hi Geliang, On 05/09/2026 10:26, Geliang Tang wrote: > Hi Matt, > > On Sat, 2026-08-15 at 00:28 +0200, Matthieu Baerts (NGI0) wrote: >> In case of poll timeout, it might be too late to print the stats >> after >> the socket closure. >> >> Now, in case of poll timeout, 'ss' and 'nstat' are invoked from >> mptcp_connect to print the stats before exiting. This should help >> debugging poll timeout issues. >> >> Note: for this "workaround", system() is used for debugging purposes > > This print_err_stats() implementation is basically the same as > mptcp_lib_pr_err_stats() in the shell, right? Correct. > I think it's better to use mptcp_lib_pr_err_stats() in the shell to > print the information. In mptcp_connect.c, when a poll timeout occurs, > we send a signal to the shell and don't close the socket immediately - > we wait for the shell to finish printing the information before closing > it. What do you think of this approach? There's a reference > implementation in the attachment, but I haven't tested it. Thank you for your review. I agree that what you suggested is better for a tool that would be used in production. But here with the selftests, I don't think we need your long patch with a higher complexity, just for the selftests. I think it is fine to have some "system()" calls with the same ss/nstat commands compared to a patch of 50+ lines to get the same result. No? Cheers, Matt -- Sponsored by the NGI0 Core fund.
Hi Matt,
Sorry for the delayed reply.
On Tue, 2026-09-08 at 19:52 +0200, Matthieu Baerts wrote:
> Hi Geliang,
>
> On 05/09/2026 10:26, Geliang Tang wrote:
> > Hi Matt,
> >
> > On Sat, 2026-08-15 at 00:28 +0200, Matthieu Baerts (NGI0) wrote:
> > > In case of poll timeout, it might be too late to print the stats
> > > after
> > > the socket closure.
> > >
> > > Now, in case of poll timeout, 'ss' and 'nstat' are invoked from
> > > mptcp_connect to print the stats before exiting. This should help
> > > debugging poll timeout issues.
> > >
> > > Note: for this "workaround", system() is used for debugging
> > > purposes
> >
> > This print_err_stats() implementation is basically the same as
> > mptcp_lib_pr_err_stats() in the shell, right?
>
> Correct.
>
> > I think it's better to use mptcp_lib_pr_err_stats() in the shell to
> > print the information. In mptcp_connect.c, when a poll timeout
> > occurs,
> > we send a signal to the shell and don't close the socket
> > immediately -
> > we wait for the shell to finish printing the information before
> > closing
> > it. What do you think of this approach? There's a reference
> > implementation in the attachment, but I haven't tested it.
> Thank you for your review. I agree that what you suggested is better
> for
> a tool that would be used in production. But here with the selftests,
> I
> don't think we need your long patch with a higher complexity, just
> for
> the selftests. I think it is fine to have some "system()" calls with
> the
> same ss/nstat commands compared to a patch of 50+ lines to get the
> same
> result. No?
I agree with you - simplicity is a plus as well.
I tested it and it works. So LGTM!
Reviewed-by: Geliang Tang <geliang@kernel.org>
However, we need to handle something in mptcp_connect.sh afterwards.
Otherwise, when a timeout occurs, we'll get two duplicate outputs: one
from mptcp_connect, which is the log added by this patch, and one from
mptcp_connect.sh, which is an invalid log. I think in this case we
should ignore the latter, for example by adding the following to
mptcp_connect.sh:
do_transfer()
{
...
mptcp_lib_pr_fail "client exit code $retc, server $rets"
if [ ${rets} -ne 2 ] && [ ${retc} -ne 2 ]; then
mptcp_lib_pr_err_stats "${listener_ns}" "${connector_ns}" "${port}"
fi
...
}
What do you think? If you don't have time, I can submit this follow-up
patch as well.
Thanks,
-Geliang
>
> Cheers,
> Matt
Hi Geliang,
Thank you for your patience.
On 21/09/2026 09:52, Geliang Tang wrote:
> Hi Matt,
>
> Sorry for the delayed reply.
>
> On Tue, 2026-09-08 at 19:52 +0200, Matthieu Baerts wrote:
>> Hi Geliang,
>>
>> On 05/09/2026 10:26, Geliang Tang wrote:
>>> Hi Matt,
>>>
>>> On Sat, 2026-08-15 at 00:28 +0200, Matthieu Baerts (NGI0) wrote:
>>>> In case of poll timeout, it might be too late to print the stats
>>>> after
>>>> the socket closure.
>>>>
>>>> Now, in case of poll timeout, 'ss' and 'nstat' are invoked from
>>>> mptcp_connect to print the stats before exiting. This should help
>>>> debugging poll timeout issues.
>>>>
>>>> Note: for this "workaround", system() is used for debugging
>>>> purposes
>>>
>>> This print_err_stats() implementation is basically the same as
>>> mptcp_lib_pr_err_stats() in the shell, right?
>>
>> Correct.
>>
>>> I think it's better to use mptcp_lib_pr_err_stats() in the shell to
>>> print the information. In mptcp_connect.c, when a poll timeout
>>> occurs,
>>> we send a signal to the shell and don't close the socket
>>> immediately -
>>> we wait for the shell to finish printing the information before
>>> closing
>>> it. What do you think of this approach? There's a reference
>>> implementation in the attachment, but I haven't tested it.
>> Thank you for your review. I agree that what you suggested is better
>> for
>> a tool that would be used in production. But here with the selftests,
>> I
>> don't think we need your long patch with a higher complexity, just
>> for
>> the selftests. I think it is fine to have some "system()" calls with
>> the
>> same ss/nstat commands compared to a patch of 50+ lines to get the
>> same
>> result. No?
>
> I agree with you - simplicity is a plus as well.
>
> I tested it and it works. So LGTM!
>
> Reviewed-by: Geliang Tang <geliang@kernel.org>
>
>
> However, we need to handle something in mptcp_connect.sh afterwards.
> Otherwise, when a timeout occurs, we'll get two duplicate outputs: one
> from mptcp_connect, which is the log added by this patch, and one from
> mptcp_connect.sh, which is an invalid log. I think in this case we
> should ignore the latter, for example by adding the following to
> mptcp_connect.sh:
>
> do_transfer()
> {
> ...
> mptcp_lib_pr_fail "client exit code $retc, server $rets"
> if [ ${rets} -ne 2 ] && [ ${retc} -ne 2 ]; then
> mptcp_lib_pr_err_stats "${listener_ns}" "${connector_ns}" "${port}"
> fi
> ...
> }
>
> What do you think? If you don't have time, I can submit this follow-up
> patch as well.
Is it really an issue to have two stats outputs? They are not
duplicated: one is explicitly printing stats before socket closure, and
the other one after.
Ignoring the 2nd output is easy, but this output can be valuable? Also,
I don't think there will be a timeout issue on both the client and the
server. Likely only one of them will timeout, and the additional check
you suggest is not needed.
So OK like that?
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
Hi Matt,
On Thu, 2026-10-22 at 09:58 +0200, Matthieu Baerts wrote:
> Hi Geliang,
>
> Thank you for your patience.
>
> On 21/09/2026 09:52, Geliang Tang wrote:
> > Hi Matt,
> >
> > Sorry for the delayed reply.
> >
> > On Tue, 2026-09-08 at 19:52 +0200, Matthieu Baerts wrote:
> > > Hi Geliang,
> > >
> > > On 05/09/2026 10:26, Geliang Tang wrote:
> > > > Hi Matt,
> > > >
> > > > On Sat, 2026-08-15 at 00:28 +0200, Matthieu Baerts (NGI0)
> > > > wrote:
> > > > > In case of poll timeout, it might be too late to print the
> > > > > stats
> > > > > after
> > > > > the socket closure.
> > > > >
> > > > > Now, in case of poll timeout, 'ss' and 'nstat' are invoked
> > > > > from
> > > > > mptcp_connect to print the stats before exiting. This should
> > > > > help
> > > > > debugging poll timeout issues.
> > > > >
> > > > > Note: for this "workaround", system() is used for debugging
> > > > > purposes
> > > >
> > > > This print_err_stats() implementation is basically the same as
> > > > mptcp_lib_pr_err_stats() in the shell, right?
> > >
> > > Correct.
> > >
> > > > I think it's better to use mptcp_lib_pr_err_stats() in the
> > > > shell to
> > > > print the information. In mptcp_connect.c, when a poll timeout
> > > > occurs,
> > > > we send a signal to the shell and don't close the socket
> > > > immediately -
> > > > we wait for the shell to finish printing the information before
> > > > closing
> > > > it. What do you think of this approach? There's a reference
> > > > implementation in the attachment, but I haven't tested it.
> > > Thank you for your review. I agree that what you suggested is
> > > better
> > > for
> > > a tool that would be used in production. But here with the
> > > selftests,
> > > I
> > > don't think we need your long patch with a higher complexity,
> > > just
> > > for
> > > the selftests. I think it is fine to have some "system()" calls
> > > with
> > > the
> > > same ss/nstat commands compared to a patch of 50+ lines to get
> > > the
> > > same
> > > result. No?
> >
> > I agree with you - simplicity is a plus as well.
> >
> > I tested it and it works. So LGTM!
> >
> > Reviewed-by: Geliang Tang <geliang@kernel.org>
> >
> >
> > However, we need to handle something in mptcp_connect.sh
> > afterwards.
> > Otherwise, when a timeout occurs, we'll get two duplicate outputs:
> > one
> > from mptcp_connect, which is the log added by this patch, and one
> > from
> > mptcp_connect.sh, which is an invalid log. I think in this case we
> > should ignore the latter, for example by adding the following to
> > mptcp_connect.sh:
> >
> > do_transfer()
> > {
> > ...
> > mptcp_lib_pr_fail "client exit code $retc, server $rets"
> > if [ ${rets} -ne 2 ] && [ ${retc} -ne 2 ]; then
> > mptcp_lib_pr_err_stats "${listener_ns}" "${connector_ns}"
> > "${port}"
> > fi
> > ...
> > }
> >
> > What do you think? If you don't have time, I can submit this
> > follow-up
> > patch as well.
>
> Is it really an issue to have two stats outputs? They are not
> duplicated: one is explicitly printing stats before socket closure,
> and
> the other one after.
>
> Ignoring the 2nd output is easy, but this output can be valuable?
> Also,
> I don't think there will be a timeout issue on both the client and
> the
> server. Likely only one of them will timeout, and the additional
> check
> you suggest is not needed.
>
> So OK like that?
OK, let's keep this patch as is. Please merge it:
Reviewed-by: Geliang Tang <geliang@kernel.org>
Thanks,
-Geliang
>
> Cheers,
> Matt
Hi Matthieu,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- 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/31847744292
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/2da643328f05
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1146325
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-normal
For 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)
© 2016 - 2026 Red Hat, Inc.