arun11299 / cpp-subprocess

Subprocessing with modern C++
Other
449 stars 90 forks source link

wait() / communicate() can hang indefinitely with no recourse #74

Open bcov77 opened 2 years ago

bcov77 commented 2 years ago

The issue here is basically that there's no way to specify a timeout. I hacked the code myself with a new exception type, a global constant for timeout, and a few std::chrono calls in wait_for_child_exit(). However, my global constant probably isn't a great way to do this.

Why is this a problem?

Consider that you have a very important process which cannot crash or hang which needs to run a program that potentially behaves badly. If the other program does behave badly (monitored through pipes, i/o, etc), one would probably like to kill and print the stdout/stderr.

Now, presumably kill(9); communicate(); will always return quickly. But suppose it doesn't and your other program really is just deadlocked. Now your main program is going to hang and there's nothing you can do about it.