Skip to content

Commit 0ddc62f

Browse files
authored
Fix crash when writing to a Barrier more than once (#637)
* Fix crash when writing to a Barrier more than once * Less confusing now
1 parent 7e9326b commit 0ddc62f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Development/IDE/Core/Shake.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,15 @@ newSession IdeState{shakeExtras=ShakeExtras{..}, ..} systemActs userActs = do
497497
let runInShakeSession :: forall a . Action a -> IO (IO a)
498498
runInShakeSession act = do
499499
res <- newBarrier
500-
let act' = actionCatch @SomeException (Right <$> act) (pure . Left)
501-
atomically $ writeTQueue actionQueue (act' >>= liftIO . signalBarrier res)
500+
let act' = do
501+
-- work gets reenqueued when the Shake session is restarted
502+
-- it can happen that a work item finished just as it was reenqueud
503+
-- in that case, skipping the work is fine
504+
alreadyDone <- liftIO $ isJust <$> waitBarrierMaybe res
505+
unless alreadyDone $ do
506+
x <- actionCatch @SomeException (Right <$> act) (pure . Left)
507+
liftIO $ signalBarrier res x
508+
atomically $ writeTQueue actionQueue act'
502509
return (waitBarrier res >>= either throwIO return)
503510

504511
-- Cancelling is required to flush the Shake database when either

0 commit comments

Comments
 (0)