Skip to content

Commit cdbc1a4

Browse files
committed
Timeout removePathForcibly in moduleWorkspace
1 parent 60ed9f1 commit cdbc1a4

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/Hedgehog/Extras/Test/Base.hs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ import qualified System.Environment as IO
148148
import qualified System.Info as IO
149149
import qualified System.IO as IO
150150
import qualified System.IO.Temp as IO
151+
import qualified System.Timeout as IO
151152

152153
{- HLINT ignore "Reduce duplication" -}
153154

@@ -208,17 +209,19 @@ workspace prefixPath f =
208209
=> FilePath
209210
-> Int
210211
-> m ()
211-
removeWorkspaceRetries ws retries = GHC.withFrozenCallStack $ do
212-
result <- try (liftIO (IO.removePathForcibly ws))
213-
case result of
214-
Right () -> return ()
215-
Left (_ :: IOException) -> do
216-
if retries > 0
217-
then do
218-
liftIO (IO.threadDelay 100000) -- wait 100ms before retrying
219-
removeWorkspaceRetries ws (retries - 1)
220-
else do
221-
failMessage GHC.callStack "Failed to remove workspace directory after multiple attempts"
212+
removeWorkspaceRetries ws retries =
213+
GHC.withFrozenCallStack $ do
214+
result <- try (liftIO (IO.timeout (5 * 1000) (IO.removePathForcibly ws)))
215+
case result of
216+
Right (Just ()) -> return ()
217+
Right Nothing -> pure ()
218+
Left (_ :: IOException) -> do
219+
if retries > 0
220+
then do
221+
liftIO (IO.threadDelay 100000) -- wait 100ms before retrying
222+
removeWorkspaceRetries ws (retries - 1)
223+
else do
224+
failMessage GHC.callStack "Failed to remove workspace directory after multiple attempts"
222225

223226

224227
-- | Create a workspace directory which will exist for at least the duration of

0 commit comments

Comments
 (0)