From 0b5e46fc7589efe001836afb0dd310b8ca4f8582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Fri, 20 Nov 2026 16:30:03 +0100 Subject: Kill remaining processes started by task recipe Changelog: Make sure to terminate processes started by task recipe after it finishes. --- src/Job.hs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/Job.hs') diff --git a/src/Job.hs b/src/Job.hs index 45cc827..b40f450 100644 --- a/src/Job.hs +++ b/src/Job.hs @@ -48,6 +48,7 @@ import System.Exit import System.FilePath import System.FilePath.Glob import System.IO +import System.IO.Error import System.IO.Temp import System.Posix.Signals import System.Process @@ -529,20 +530,24 @@ runJob job uses checkoutPath jdir = do Right script -> do sh <- fromMaybe "/bin/sh" <$> liftIO (lookupEnv "SHELL") return ( proc sh [], script ) - (Just hin, _, _, hp) <- liftIO $ createProcess_ "" p + ( Just hin, _, _, hp ) <- liftIO $ createProcess_ "" p { cwd = Just checkoutPath , std_in = CreatePipe , std_out = UseHandle logs , std_err = UseHandle logs + , create_group = True } + Just pid <- liftIO $ getPid hp liftIO $ void $ forkIO $ do T.hPutStr hin input hClose hin - liftIO (waitForProcess hp) >>= \case + let killCreatedProcessGroup = do + handleJust (\case e | isDoesNotExistError e -> Just (); _ -> Nothing) return $ do + signalProcessGroup sigKILL pid + waitForProcess hp + liftIO (waitForProcess hp `finally` killCreatedProcessGroup) >>= \case ExitSuccess -> return () - ExitFailure n - | fromIntegral n == -sigINT -> throwError JobCancelled - | otherwise -> throwError JobFailed + ExitFailure _ -> throwError JobFailed artifacts <- forM (jobArtifacts job) $ \( name@(ArtifactName tname), pathPattern ) -> do let adir = jdir "artifacts" T.unpack tname -- cgit v1.2.3