Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not try to cancel NULL thread (causing Segmentation fault) #1801

Merged

Conversation

davidBar-On
Copy link
Contributor

  • Version of iperf3 (or development branch, such as master or
    3.1-STABLE) to which this pull request applies:

  • Issues fixed (if any): none

  • Brief description of code changes (suitable for use as a commit message):

Suggested Bug fix: thread id 0 is not regarded as illegal id (at least in Ubuntu Linux), and pthread_cancel() crashes (Segmentation fault) when trying to cancel a thread with id 0. That happens if streams creation was successful, but there was a failure before all threads are created. The problem happened to me at work and I can reproduce it in my private PC.

The suggested fix is to add an indication thread_created per stream to indicate if the thread was created for the stream, and try to cancel the stream's thread only if it was created.

Copy link
Contributor

@bmah888 bmah888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! This looks like a good change (set of changes). Just one comment, mostly FYI and not something that needs to be "fixed". Just need to do some testing on this...

src/iperf_api.c Outdated Show resolved Hide resolved
@bmah888
Copy link
Contributor

bmah888 commented Dec 2, 2024

@davidBar-On I have just one more question...the code looks good according to my reading of it...I haven't been able to trigger the original bug to compare the original and fixed behavior. Any suggestion about how I can test this? Thanks!

@davidBar-On
Copy link
Contributor Author

@bmah888, the way I tested it was by causing the client to fail after the streams creation, just before the threads creation. E.g., in iperf_client_api.c: adding goto cleanup_and_fail; just before:

                SLIST_FOREACH(sp, &test->streams, streams) {
                    if (pthread_create(&(sp->thr), &attr, &iperf_client_worker_run, sp) != 0) {
                        ...         

@bmah888
Copy link
Contributor

bmah888 commented Dec 3, 2024

@bmah888, the way I tested it was by causing the client to fail after the streams creation, just before the threads creation. E.g., in iperf_client_api.c: adding goto cleanup_and_fail; just before:

                SLIST_FOREACH(sp, &test->streams, streams) {
                    if (pthread_create(&(sp->thr), &attr, &iperf_client_worker_run, sp) != 0) {
                        ...         

Thanks! I'm still not able to reproduce the segmentation fault, but with the help of --debug I can see that the code in this PR is preventing iperf3 from trying to cancel non-existent threads, which is probably close enough.

@bmah888 bmah888 merged commit 510cf65 into esnet:master Dec 3, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants