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

Fix race on open3/fork and session->register($pid) call -- second attempt #22

Merged
merged 4 commits into from
Nov 30, 2021

Conversation

cfconrad
Copy link
Collaborator

This is a second option to fix this issue, see #21.
I would like to discuss what way fit's more.

The disadvantage of this process is, that we change the SIGMASK and the child will inherit it.
But we only care of SIG_CHLD and this is reset in fork() path anyway.

The `collect_status` handler must be set before we fork/open3 a
subprocess, otherwise we have a potential race that we miss that event.
@cfconrad cfconrad changed the title Fix race on open3/fork and session->register($pid) call -- second attempt [WIP] Fix race on open3/fork and session->register($pid) call -- second attempt Nov 29, 2021
@cfconrad cfconrad force-pushed the fix_race_on_register_process_v2 branch from 0b00399 to 483476e Compare November 29, 2021 14:35
@cfconrad
Copy link
Collaborator Author

set to WIP as this c1c0ba9 test fails with this code!

@cfconrad cfconrad force-pushed the fix_race_on_register_process_v2 branch from c1c0ba9 to 16621eb Compare November 29, 2021 21:30
@cfconrad cfconrad changed the title [WIP] Fix race on open3/fork and session->register($pid) call -- second attempt Fix race on open3/fork and session->register($pid) call -- second attempt Nov 29, 2021
If a sub process is exiting before the parent process calls
`session->register()` we miss the `collect_status` thus the process end
up in `session->orphan()`.
Also we did a lot of work inside the signal handler context. This is
actually bad as well.

This fix change the work of the signalhandler to a minimum, it just
collect the process info and store it inside of an array.
Then on each `is_running()` call, we process this list and call the
corresponding events.
The `session->reset()` method should also reset the handler function,
otherwise the sighandler doesn't work in a subprocess.
@cfconrad cfconrad force-pushed the fix_race_on_register_process_v2 branch from 16621eb to a37fc97 Compare November 29, 2021 21:35
@cfconrad
Copy link
Collaborator Author

I changed this code. The SIG_CHLD handler now just collect the process info and later, not inside the signal handler context, we consume it and emit all these events.
With this done, we also fix the issue.

@foursixnine
Copy link
Member

Thanks @cfconrad!!

@foursixnine foursixnine merged commit b88fd4f into openSUSE:master Nov 30, 2021
@cfconrad cfconrad mentioned this pull request Nov 30, 2021
@cfconrad cfconrad deleted the fix_race_on_register_process_v2 branch December 14, 2021 20:04
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.

None yet

2 participants