Skip to content

Don't mark a thread as joinable when it calls exit() #15105

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

Merged
merged 1 commit into from
Sep 24, 2021
Merged

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Sep 23, 2021

The previous behavior was that ExitStatus was thrown which ends up
calling emscripten_thread_exit and marking the current thread as
joinable.

This this bug was masking several failures in the posixtest suite
which have always be failing but were not being recognised as such.

Note that we have to use the message queue rather than postMessage
to deliver the exitProcess message since postMessage will not interrupt
the main thread if its blocking on pthread_join.

Modify the existing test so that it fails if pthead_join even returns.

The tests that were passing before are basically of the form:

void thread_func() {
   ...
   exit(NON_ZERO);   // <- should exit the entire program without waking joining threads
}

int mai() {
    pthread_join(thread_func);
    return 0;  //  <- join should never return so we should never get here.
}

Such a program would return 0 without this fix.

Fixes: #14993

@sbc100 sbc100 requested review from kleisauke and kripken September 23, 2021 01:00
@sbc100 sbc100 force-pushed the no_joinable_on_exit branch 5 times, most recently from 0c83f1e to 26cfbc7 Compare September 23, 2021 07:00
@sbc100 sbc100 requested a review from juj September 23, 2021 07:02
@sbc100 sbc100 changed the title Don't mark a thread a joinable when it calls exit() Don't mark a thread as joinable when it calls exit() Sep 23, 2021
@sbc100 sbc100 force-pushed the no_joinable_on_exit branch 3 times, most recently from ffa6a45 to d38cde3 Compare September 23, 2021 07:10
@sbc100 sbc100 force-pushed the no_joinable_on_exit branch 2 times, most recently from d1342d6 to ca5b941 Compare September 23, 2021 15:15
@sbc100 sbc100 requested a review from kleisauke September 23, 2021 15:22
Copy link
Collaborator

@kleisauke kleisauke left a comment

Choose a reason for hiding this comment

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

LGTM % comments

Comment on lines 1239 to 1253
$exitProcess__deps: ['$handleException', 'exit'],
$exitProcess__deps: ['exit',
Copy link
Collaborator

Choose a reason for hiding this comment

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

The $exitProcess__deps line is duplicated now with different array values (probably the latter takes precedence over the former).

@sbc100 sbc100 force-pushed the no_joinable_on_exit branch from ca5b941 to 3dddeb6 Compare September 23, 2021 17:33
@sbc100 sbc100 enabled auto-merge (squash) September 23, 2021 17:36
@sbc100 sbc100 force-pushed the no_joinable_on_exit branch 3 times, most recently from 80e2ad2 to 357454e Compare September 23, 2021 19:35
The previous behavior was that ExitStatus was thrown which ends up
calling emscripten_thread_exit and marking the current thread as
join-able.

This this bug was masking several failures in the posixtest suite
which have always be failing but were not being recognized as such.

Note that we have to use the message queue rather than postMessage
to deliver the `exitProcess` message since postMessage will not interrupt
the main thread if its blocking on pthread_join.

Modify the existing test so that it fails if pthead_join even returns.

Fixes: #14993
@sbc100 sbc100 force-pushed the no_joinable_on_exit branch from 357454e to ea78e10 Compare September 23, 2021 23:33
@sbc100 sbc100 merged commit 8ded0b8 into main Sep 24, 2021
@sbc100 sbc100 deleted the no_joinable_on_exit branch September 24, 2021 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test_pthread_exit_process suspicious log message on Node
2 participants