This probably avoids the situation that caused the exception to be
thrown. It also makes sure that both threads end up canceled in the end,
while before the exception from wait outt could have caused errt to
never be waited on.
outt <- async $ tryIO (outfilter outh) >> hClose outh
errt <- async $ tryIO (errfilter errh) >> hClose errh
ret <- waitForProcess pid
+
-- Normally, now that the process has exited, the threads
-- will finish processing its output and terminate.
-- But, just in case the process did something evil like
-- openssh.)
void $ tryNonAsync $ race_
(wait outt >> wait errt)
- (threadDelaySeconds (Seconds 2) >> cancel outt >> cancel errt)
+ (threadDelaySeconds (Seconds 2))
+ cancel outt
+ cancel errt
+
return ret
go _ _ _ _ = error "internal"