aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-10-13 12:16:15 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-10-13 12:16:15 +0200
commitd00e385942a90e7e0600ee878db5d6c9120a6558 (patch)
treee5686e011f4d66e08d610544cda3d63bfea3bf27
parente66534eefb5979c1ec5e0a28e9c29969ae2c9884 (diff)
fix race on repository watch
-rw-r--r--backend/app/Main.hs17
1 files changed, 13 insertions, 4 deletions
diff --git a/backend/app/Main.hs b/backend/app/Main.hs
index c31ea7d..917a6d9 100644
--- a/backend/app/Main.hs
+++ b/backend/app/Main.hs
@@ -13,7 +13,7 @@ import Control.Concurrent
import Control.Concurrent.STM
import Control.Exception (throwIO)
import Control.Monad
-import Control.Monad.Catch (Exception)
+import Control.Monad.Catch (Exception, SomeException, catch, displayException)
import Control.Monad.Trans (liftIO)
import Data.Aeson qualified as J
import Data.Aeson.KeyMap qualified as JM
@@ -127,13 +127,22 @@ watch repoT root ref = do
addWatch i [Create, MoveIn] ".git/refs/heads" $ \e -> do
when (e.filePath == B.fromString (takeBaseName (T.unpack ref))) do
atomically (writeTQueue qT e)
+ repo <- initRepo root ref
+ atomically do putTMVar repoT repo
forever do
- repo <- initRepo root ref
- atomically do putTMVar repoT repo
_ <- atomically do
let loop = maybe (pure ()) (const loop) =<< tryReadTQueue qT
readTQueue qT >> loop
- _ <- atomically do takeTMVar repoT
+ repo' <- atomically do takeTMVar repoT
+ catch
+ ( do
+ repo <- initRepo root ref
+ atomically do putTMVar repoT repo
+ )
+ ( \(e :: SomeException) -> do
+ printf "warning: %s\n" (displayException e)
+ atomically do putTMVar repoT repo'
+ )
pure ()
initRepo :: FilePath -> G.RefName -> IO Repo