Selecting for duration of timeout can cause hang

When specifying a timeout, the subprocess used to select for timeout seconds on the stdout, stderr pipes.

This creates a race condition and can cause the `Subprocess#execute` to hang for the full timeout interval if the process has already exited and no more output is send to the pipes.

This race is happening with a higher probability if the subprocess is generating a lot of output.
Merge pull request #4341 from databus23/patch-2

core: selecting for duration of timeout can cause hang