From 4466c1001d885ea5a5e4c9e073d347e86b92a8be Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 10 Aug 2020 16:33:58 -0400 Subject: [PATCH] improve slightly 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. --- Utility/Metered.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Utility/Metered.hs b/Utility/Metered.hs index 3a9d3620a7..e62a5bba4a 100644 --- a/Utility/Metered.hs +++ b/Utility/Metered.hs @@ -319,6 +319,7 @@ outputFilter cmd params environ outfilter errfilter = 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 @@ -330,7 +331,10 @@ outputFilter cmd params environ outfilter errfilter = -- 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"