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. Reviewed-by: Geliang Tang Signed-off-by: Matthieu Baerts (NGI0) --- 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 178d98d91fea..8c788977e594 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; @@ -658,6 +671,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; } @@ -1196,6 +1210,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; } -- 2.55.0