-
Notifications
You must be signed in to change notification settings - Fork 116
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
POSIX multi-thread parallel childs invoked with piped std_in often do not receive STDIN close #169
Comments
The child processes are inheriting the pipe input filehandle and therefore the pipe can never truly close. Pipes should be created with O_CLOEXEC. |
@Boronak It would be nice if you kept your issue reporting to one issue instead of misusing comments like this. |
Can you try putting the |
@klemens-morgenstern Sorry for being so unclear. The workaround looks like this:
|
@Boronak does that work without |
@klemens-morgenstern Yes.
|
Please note there are some other problems with this code. As @klemens-morgenstern correctly points out the |
Yes, I confirm that creating inputStream using pipe created with O_CLOEXEC helps to fix my issue. Thanks! It is still little confusing to me why the O_CLOEXEC flag was not needed when running only one process then (eg. same example without parallel threads works correctly without it)? |
And BTW, this did not help. It then simply blocks on getline(outputStream, line) (as child ("cat") endlessly runs and waits for STDIN to be closed). |
@martlaak-gmail The pipe handles passed to |
Yes, but exactly the same happens when only one child is launched. Why it is never problem then? |
Single thread:
Multi thread:
|
I might have some insight on this. I was facing the same issue where launching a single child process would have no problem, but launching multiple in a multi-threaded fashion caused none of them to receive data from stdin. I tried to workaround by implementing the code myself using The workaround is to add a mutex to the child spawning, which ensures the calls to I don't think this library makes any MT-safety promises anywhere, but I think it should be safe to assume that launching a new process should be MT-safe, although that's my own opinion. |
For example this parallel POSIX child invoke with std_in from pipe often hangs on requestProcess->wait(), because child never receives STDIN close:
Note, that:
The text was updated successfully, but these errors were encountered: