Comments (19)
Weird. Alright, I'll look into it. It might actually be the same bug for all your issues.
from process.
I think it's a bug in the async stdin version, because (I fear) that doesn't close the pipe when done. Thus cat stays active since the pipe is open.
Can you test using a different input method? i won't be able to look into it before next week.
from process.
I've found a number of other seemingly related deadlocks. Like maybe #65. As well as this:
std::string data = "some data to send to cat";
std::future<std::string> result;
boost::asio::io_service ios;
boost::process::pipe p;
opstream out;
spawn("cat", std_in<out, std_out>p);
spawn("cat", std_in<p, std_out>result, ios);
std::thread t([&]() { out << data << std::flush; out.pipe().close(); });
// run blocks forever.
ios.run();
t.join();
However, this slightly different version works as expected:
std::string data = "some data to send to cat";
std::future<std::string> result;
boost::asio::io_service ios;
boost::process::pipe p;
opstream out;
spawn("cat", std_in<out, std_out>result, ios);
std::thread t([&]() { out << data << std::flush; out.pipe().close(); });
ios.run();
t.join();
Maybe they are all caused by the same underlying issue. I am not sure.
from process.
I assume you're on linux, right?
Can you try out what happens if you change spawn
to async_system
and put some dummy handler in?
I.e. async_system(ios, [](const boost::system::error_code & ec, int ret){}, ("cat", std_in<out, std_out>p);
from process.
Yeah, using Ubuntu 16.04.
I tried replacing spawn
with async_system
and it still hangs just like before.
from process.
Sweet, thanks :)
Yeah, that's my suspicion as well.
from process.
Do you use boost 1.68 or the current HEAD of the git repo?
from process.
from process.
Ok, that should, but could you use the currend develop-HEAD just to be sure?
from process.
Just grabbed the develop-HEAD of https://github.com/boostorg/process and got the same results, same things work and same things still hang.
from process.
I am experimenting sort of the same issue. Although my code only binds stderr and stdout output streams, whenever I execute the context run function it will hang in there even when the child process is gone.
something like:
child = boost::process::child(path, args, group, bp::std_out > stdout_stream, bp::std_err > stderr_stream, ios);
[..]
ios.run();
child.wait();
When I submit a kill signal to the child process, the parent process is still waiting for IO. child.wait()
is never executed.
Is this the same issue?
If so, could we rename this thread to remove the input keyword?
from process.
@LuisAyuso I would need more about your use-case - do the streams refer to an async_pipe
?
from process.
my stream objects are a custom class, they wrap an async_pipe, hold a buffer to accumulate output, and re-register the callback after every read.
I noticed that the read callback is never invoked after child process dead, not even to notify an error.
from process.
Weird, which system are you on? Normally you should get an EOF.
What do you call to start the read operation?
from process.
Sorry for fragmented information, let's see if we manage to have a proper report ;)
I am using Ubuntu 18.04, with gcc 7.4.0
The Boost version is 1.69
I have been cleaning the code so I can show something here:
ba::io_context ios;
std::vector<char> stdout_buffer(1024);
auto out_buffer{ba::buffer(stdout_buffer)};
bp::async_pipe std_out{ios};
std::function<void(const boost::system::error_code &ec, size_t s)> stdout_callback;
stdout_callback = [&](const boost::system::error_code &ec, size_t s) {
if (ec)
return;
auto v = std::string_view(&stdout_buffer.front(), s);
fmt::print("stdout: {}", v);
std_out.async_read_some(out_buffer, stdout_callback);
};
std::vector<char> stderr_buffer(1024);
auto err_buffer{ba::buffer(stderr_buffer)};
bp::async_pipe std_err{ios};
std::function<void(const boost::system::error_code &ec, size_t s)> stderr_callback;
stderr_callback = [&](const boost::system::error_code &ec, size_t s) {
if (ec)
return;
auto v = std::string_view(&stdout_buffer.front(), s);
fmt::print("stderr: {}", v);
std_err.async_read_some(err_buffer, stderr_callback);
};
std_out.async_read_some(out_buffer, stdout_callback);
std_err.async_read_some(err_buffer, stderr_callback);
child =
bp::child(path, args, group, bp::std_out > std_out, bp::std_err > std_err, ios);
ios.run();
child.wait();
The behavior of this code is the same as the one reported originally.
ios.run()
blocks event when the child process is dead.child.wait()
is never executed if the child process is externally killed
from process.
This is weird indeed. Can you add bp::on_exit
to check if this gets called?
Also, where does the group
come from?
from process.
Group is currently default initialized. (bp::group)
on_exit works, I can use it now to shut down the io context (ios.stop()
) and let the program proceed to child.wait()
I can use now this as a workaround, it is way better than my original one (which was to put io.run in a separate thread)
from process.
The better workaround would be to close the pipes from the on-exit handler.
Can you try the current master branch and see if it fixes the issue?
from process.
So I encountered this issue today, but I had also encountered the same effect in some rust async code in tokio. So because of the possibility they could be the same issue here is my associated issue and more importantly the PR that fixed it tokio-rs/tokio#2255 tokio-rs/tokio#2218
from process.
Related Issues (20)
- `boost::process::shell` documentation lacking HOT 2
- Process v2 and process_environment does not link. HOT 4
- [v2] error: overloaded process constructor if passing an executor HOT 2
- [v2] vfork_launcher undefined behaviour HOT 1
- Is it possible to add support for string_view? HOT 2
- boost::system::error_code not included in pipe_in/pipe_out when BOOST_PROCESS_USE_STD_FS is defined
- Process V2: Example fails to build when using BOOST_ASIO_SEPARATE_COMPILATION HOT 2
- Setting the capacity of the underline pipe. Linux only HOT 4
- Missing dependency on scope_exit with CMake build
- bp::environment::native_handle() cannot be compiled on Linux HOT 1
- Including boost/process.hpp causes build failure on Windows HOT 8
- [v2] Using async_execute with bind_cancellation_slot HOT 7
- Is it a typo mistake for "tempalte" in environment.hpp ?
- clang-15 error: expected unqualified-id due to dirfd macro in macOS 14 SDK
- clang-10 warning: comparison of integers of different signs: 'typename iterator_traits<__wrap_iter<char *> >::difference_type' (aka 'long') and 'const std::size_t' (aka 'const unsigned long')
- [Linux] boost::process:: child ::wait_until is not thread-safe HOT 6
- Boost CMake testing procedure doesn't work for Process
- [v2][Linux] process_is_running() returns false with musl libc
- boost\process\pipe.hpp(132,5): warning C4297: 'boost::process::basic_pipebuf<char,std::char_traits<char>>::~basic_pipebuf': function assumed not to throw an exception but does
- pipe_out leaks pipe source fd when redirecting both stdout and stderr to same pipe
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from process.