Wait for subprocess output before releasing resources
This commit is contained in:
@@ -2,7 +2,6 @@ package subprocess
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
@@ -80,12 +79,7 @@ func terminateAndReap(tree ownedProcessTree, waitCh <-chan error) (waitErr, clea
|
||||
case <-timer.C:
|
||||
}
|
||||
cleanupErr = joinErrors(cleanupErr, tree.TerminateForcefully())
|
||||
forcefulTimer := time.NewTimer(forcefulTerminationWait)
|
||||
defer forcefulTimer.Stop()
|
||||
select {
|
||||
case waitErr = <-waitCh:
|
||||
return waitErr, cleanupErr
|
||||
case <-forcefulTimer.C:
|
||||
return nil, joinErrors(cleanupErr, fmt.Errorf("owned subprocess did not reap within %s after forceful termination", forcefulTerminationWait))
|
||||
}
|
||||
// Process termination and output copying are not complete until Wait returns.
|
||||
// Keep ownership of command state and output writers even if I/O is delayed.
|
||||
return <-waitCh, cleanupErr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user