job: Only force-close stdout/stderr when the job exits

stdout/stderr should only be closed after the job truly exits, or else we can
lose data sent by it.
Merge PR #1424 'Only force-close stdout/stderr when the job exits'