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

[Linux] boost::process:: child ::wait_until is not thread-safe #347

Open
AlexeyZaharov opened this issue Oct 30, 2023 · 6 comments
Open

Comments

@AlexeyZaharov
Copy link

Hi! I faced with the problem that my process hangs up while it uses wait_until() of child::process. So I watched boost code and find that boost::process:: child ::wait_until is not thread-safe

  1. struct signal_interceptor_t is used for setting custom reaction on signal with using system ::signal. So handler_func is a new handler and sigchld_handler is setting for previous handler
  2. The problem is that signal handler - atribut of the process, not thread, so if the next thread call ::signal then sigchld_handler is setting for handler_func
  3. Which thread will be used for handle signal is undefined. So thread with sigchld_handler == handler_func can be used! And this cause infinite loop
  4. You can face with the problem in this code, which uses problem part of wait_until. (On my system signals are handled by main thread). Also attach out of the programm
    bug_wait_until.cpp.txt
    out.txt

So can you update your documentation with this note please?

UPD: After I write this issue I found the same:
POSIX wait_for() crashes when multiple threads run it simultaneously
POSIX wait_for - stack overflow
child::wait_for() may block indefinitely

@klemens-morgenstern
Copy link
Collaborator

I deprecated them, they're generally unsafe.

@AlexeyZaharov
Copy link
Author

Can you update documentation with information about deprecation please? I can`t find this info

@jens-diewald
Copy link

I, too, would appreciate information on the deprecation.
Specifically, on Windows, these functions are fine, right?
Do you plan to remove them in a future release?

@rroquetto-uptycs
Copy link

@klemens-morgenstern Following up on the previous comments, do you have any references on the rationale for the deprecation, so that I can better understand what the issue is and look for alternatives moving forward?
Thanks!

@klemens-morgenstern
Copy link
Collaborator

They are fine on windows, but unsafe on linux. Therefor process cant provide a portable function that is safe.

The recommendation is to use V2 and async_wait, so you can us an asio timer to create a timeout.

@rroquetto-uptycs
Copy link

Ah great, thank you very much for such a prompt response!

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

No branches or pull requests

4 participants