From 748b5b0d92188d20afd48267d3d1b9a1f25233b9 Mon Sep 17 00:00:00 2001 From: DavidBar-On Date: Sat, 14 Sep 2024 12:05:09 +0300 Subject: [PATCH 1/2] No Server error when control-channel terminates while waiting for IPERF_DONE --- src/iperf_server_api.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index 9727cdddb..15fb3f693 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -235,16 +235,24 @@ iperf_handle_message_server(struct iperf_test *test) { int rval; struct iperf_stream *sp; + signed char old_state = test->state; if (test->debug_level >= DEBUG_LEVEL_INFO) { - iperf_printf(test, "Reading new State from the Client - current state is %d-%s\n", test->state, state_to_text(test->state)); + iperf_printf(test, "Reading new State from the Client - current state is %d-%s\n", old_state, state_to_text(old_state)); } // XXX: Need to rethink how this behaves to fit API if ((rval = Nread(test->ctrl_sck, (char*) &test->state, sizeof(signed char), Ptcp)) <= 0) { if (rval == 0) { - iperf_err(test, "the client has unexpectedly closed the connection"); - i_errno = IECTRLCLOSE; + /* If control socket was closed when IPERF_DONE is expected, assume that because of race condition + * the client closed the connection before the server received the IPERF_DONE. + */ + if (old_state != DISPLAY_RESULTS) { + iperf_err(test, "the client has unexpectedly closed the connection"); + i_errno = IECTRLCLOSE; + } else { + printf("WARNING: client connection was closed when waiting for IPERF_DONE\n"); + } iperf_set_test_state(test, IPERF_DONE); return 0; } else { From a60b77a0ceff62fbd0166a035b0a28f4d9c63f30 Mon Sep 17 00:00:00 2001 From: DavidBar-On Date: Sun, 15 Sep 2024 11:13:19 +0300 Subject: [PATCH 2/2] Call warning() instead of prontf() --- src/iperf_server_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index 15fb3f693..c00259ce0 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -251,7 +251,7 @@ iperf_handle_message_server(struct iperf_test *test) iperf_err(test, "the client has unexpectedly closed the connection"); i_errno = IECTRLCLOSE; } else { - printf("WARNING: client connection was closed when waiting for IPERF_DONE\n"); + warning("client connection was closed when waiting for IPERF_DONE"); } iperf_set_test_state(test, IPERF_DONE); return 0;