-
Notifications
You must be signed in to change notification settings - Fork 47
Hangs when reading from child process on Windows #159
Comments
Ok, a key piece of information I didn't think to include actually holds the key to what may be the root cause of the issue. This code is called in parallel via Working off that assumption I added a mutex around the child constructor so that construction of a new sub process is synchronized. It work! Hack: child gfsh;
#if defined(_WINDOWS)
{
std::lock_guard<std::mutex> guard(g_child_mutex);
#endif
gfsh = child(GFSH_EXECUTABLE, args = commands, env, std_out > outStream,
std_err > errStream, std_in < null);
#if defined(_WINDOWS)
}
#endif Any chance that the fixes mentioned in the attached link can be applied to the Windows implementation of boost::process to avoid this issue? |
Another blog article with better details of the issue. https://blogs.msdn.microsoft.com/oldnewthing/20111216-00/?p=8873 |
We had a discussion about the inheritance of handles already and that's just too much work atm for me to do implement it, because it should be an optional feature. Instead of using |
Thanks! Would you recommend a good source for documentation on strands, the Boost docs are pretty sparse. Are you suggesting that the creation of the |
Yeah, I hope the following works: namespace asio = boost::asio;
io_context ioc;
strand s(ioc);
child c1, c2, c3;
s.post([&]{c1 = child(...);});
s.post([&]{c2 = child(...);});
s.post([&]{c3 = child(...);});
ioc.run();
//here the childen should be started.
I'm mentioning that because you might be running an |
I have some applications, but in proprietary code, so I can't really share that. If you need some consulting or development, feel free to write me an E-Mail. |
Were you able to resolve the issue? |
Closing due inactivity, feel free to reopen or create another one if you run into problems. |
The below code works great on MacOS, Linux and Solaris but hangs consistently on Windows under unusual conditions. It works fine on Window 2012r2 when the compile program is executed directly in a command console but hangs when it is executed as child process of CTest (CMake). It hangs in both scenarios on Windows 10. In all hangs the threads are stuck in
std::getline()
and the child processes they are reading from have exited.Code:
Stack:
Having read the warnings about synchronous IO hanging if the process has exited I switched to asynchronous IO using the
std::future<std::string>
approach. Unfortunately it exhibits a similar issue and hangs. It hangs inios::run()
:Async:
Stack:
One interesting thing to note is that the command we are executing is a java process that itself spawns a child java process before exiting. The grandchild preprocess is long living. In both of these cases, sync and async pipes, if I kill the grandchildren our executable continues. So in some way the pipe is blocked waiting for the exit of the grandchildren, the children of the child we are executing and have the pipe attached to.
The text was updated successfully, but these errors were encountered: