Skip to content

Commit

Permalink
Addition fix for issue #1696 - not cancel a thread that was not created
Browse files Browse the repository at this point in the history
  • Loading branch information
davidBar-On committed May 11, 2024
1 parent d14e93a commit 6d22cb6
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 63 deletions.
1 change: 1 addition & 0 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -4457,6 +4457,7 @@ iperf_new_stream(struct iperf_test *test, int s, int sender)
return NULL;
}
sp->pending_size = 0;
sp->thread_number = 0;

/* Set socket */
sp->socket = s;
Expand Down
110 changes: 64 additions & 46 deletions src/iperf_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,22 +742,28 @@ iperf_run_client(struct iperf_test * test)
if (sp->sender) {
int rc;
sp->done = 1;
rc = pthread_cancel(sp->thr);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADCANCEL;
errno = rc;
iperf_err(test, "sender cancel in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
goto cleanup_and_fail;
}
rc = pthread_join(sp->thr, NULL);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADJOIN;
errno = rc;
iperf_err(test, "sender cancel in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
goto cleanup_and_fail;
}
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket);
if (sp->thread_number > 0) { // if thread was created
rc = pthread_cancel(sp->thr);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADCANCEL;
errno = rc;
iperf_err(test, "sender cancel in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
goto cleanup_and_fail;
}
rc = pthread_join(sp->thr, NULL);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADJOIN;
errno = rc;
iperf_err(test, "sender cancel in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
goto cleanup_and_fail;
}
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket);
}
sp->thread_number = 0;
} else {
if (test->debug_level >= DEBUG_LEVEL_INFO)
iperf_printf(test, "Not stopping thread for FD %d as it was not created\n", sp->socket);
}
}
}
Expand Down Expand Up @@ -788,22 +794,28 @@ iperf_run_client(struct iperf_test * test)
if (!sp->sender) {
int rc;
sp->done = 1;
rc = pthread_cancel(sp->thr);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADCANCEL;
errno = rc;
iperf_err(test, "receiver cancel in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
goto cleanup_and_fail;
}
rc = pthread_join(sp->thr, NULL);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADJOIN;
errno = rc;
iperf_err(test, "receiver cancel in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
goto cleanup_and_fail;
}
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket);
if (sp->thread_number > 0) { // if thread was created
rc = pthread_cancel(sp->thr);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADCANCEL;
errno = rc;
iperf_err(test, "receiver cancel in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
goto cleanup_and_fail;
}
rc = pthread_join(sp->thr, NULL);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADJOIN;
errno = rc;
iperf_err(test, "receiver cancel in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
goto cleanup_and_fail;
}
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket);
}
sp->thread_number = 0;
} else {
if (test->debug_level >= DEBUG_LEVEL_INFO)
iperf_printf(test, "Not stopping thread for FD %d as it was not created\n", sp->socket);
}
}
}
Expand All @@ -829,20 +841,26 @@ iperf_run_client(struct iperf_test * test)
SLIST_FOREACH(sp, &test->streams, streams) {
sp->done = 1;
int rc;
rc = pthread_cancel(sp->thr);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADCANCEL;
errno = rc;
iperf_err(test, "cleanup_and_fail in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
}
rc = pthread_join(sp->thr, NULL);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADJOIN;
errno = rc;
iperf_err(test, "cleanup_and_fail in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
}
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket);
if (sp->thread_number > 0) { // if thread was created
rc = pthread_cancel(sp->thr);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADCANCEL;
errno = rc;
iperf_err(test, "cleanup_and_fail in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
}
rc = pthread_join(sp->thr, NULL);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADJOIN;
errno = rc;
iperf_err(test, "cleanup_and_fail in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
}
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket);
}
sp->thread_number = 0;
} else {
if (test->debug_level >= DEBUG_LEVEL_INFO)
iperf_printf(test, "Not stopping thread for FD %d as it was not created\n", sp->socket);
}
}
if (test->debug_level >= DEBUG_LEVEL_INFO) {
Expand Down
2 changes: 1 addition & 1 deletion src/iperf_sctp.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ iperf_sctp_recv(struct iperf_stream *sp)
sp->result->bytes_received_this_interval += r;
}
else {
if (sp->test->debug)
if (sp->test->debug_level >= DEBUG_LEVEL_DEBUG)
printf("Late receive, state = %d\n", sp->test->state);
}

Expand Down
34 changes: 20 additions & 14 deletions src/iperf_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,20 +428,26 @@ cleanup_server(struct iperf_test *test)
SLIST_FOREACH(sp, &test->streams, streams) {
int rc;
sp->done = 1;
rc = pthread_cancel(sp->thr);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADCANCEL;
errno = rc;
iperf_err(test, "cleanup_server in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
}
rc = pthread_join(sp->thr, NULL);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADJOIN;
errno = rc;
iperf_err(test, "cleanup_server in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
}
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket);
if (sp->thread_number > 0) { // if thread was created
rc = pthread_cancel(sp->thr);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADCANCEL;
errno = rc;
iperf_err(test, "cleanup_server in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
}
rc = pthread_join(sp->thr, NULL);
if (rc != 0 && rc != ESRCH) {
i_errno = IEPTHREADJOIN;
errno = rc;
iperf_err(test, "cleanup_server in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno));
}
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket);
}
sp->thread_number = 0;
} else {
if (test->debug_level >= DEBUG_LEVEL_INFO)
iperf_printf(test, "Not stopping thread for FD %d as it was not created\n", sp->socket);
}
}
i_errno = i_errno_save;
Expand Down
2 changes: 1 addition & 1 deletion src/iperf_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ iperf_tcp_recv(struct iperf_stream *sp)
sp->result->bytes_received_this_interval += r;
}
else {
if (sp->test->debug)
if (sp->test->debug_level >= DEBUG_LEVEL_DEBUG)
printf("Late receive, state = %d\n", sp->test->state);
}

Expand Down
2 changes: 1 addition & 1 deletion src/iperf_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ iperf_udp_recv(struct iperf_stream *sp)
sp->jitter += (d - sp->jitter) / 16.0;
}
else {
if (sp->test->debug)
if (sp->test->debug_level >= DEBUG_LEVEL_DEBUG)
printf("Late receive, state = %d\n", sp->test->state);
}

Expand Down

0 comments on commit 6d22cb6

Please sign in to comment.