diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2026-11-20 16:30:03 +0100 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2026-11-25 21:05:37 +0100 |
| commit | 0b5e46fc7589efe001836afb0dd310b8ca4f8582 (patch) | |
| tree | 133896d16c44c5921a9c7a7dcf62c6f0cfae55cb /src/Job.hs | |
| parent | a208b682538c8cb82246f4fb09caad1bd6421e83 (diff) | |
Kill remaining processes started by task recipe
Changelog: Make sure to terminate processes started by task recipe after it finishes.
Diffstat (limited to 'src/Job.hs')
| -rw-r--r-- | src/Job.hs | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -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 |