From 3d125791ab008d084c27c097b448fd924f703347 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 4 Feb 2019 16:23:36 -0800 Subject: [PATCH 1/3] Wait and block on the async parsing thread If we timeout an async parsing thread and return, but the parsing thread is still running, we can force a race condition in which we delete the parser before it's completed on the async thread. This patch blocks on the parsing thread until it is complete before we clean up the parser. But this might have unintended consequences for the downstream consumer (i.e. github/github). Co-Authored-By: Max Brunsfeld --- src/Parsing/TreeSitter.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Parsing/TreeSitter.hs b/src/Parsing/TreeSitter.hs index 256b91b83..4a25fdd1b 100644 --- a/src/Parsing/TreeSitter.hs +++ b/src/Parsing/TreeSitter.hs @@ -85,7 +85,7 @@ parseToAST parseTimeout language Blob{..} = bracket (liftIO TS.ts_parser_new) (l Just (Succeeded ast) -> Just ast <$ trace ("tree-sitter: parsing succeeded " <> blobPath) Nothing -> do trace $ "tree-sitter: parsing timed out " <> blobPath - Nothing <$ liftIO (TS.ts_parser_set_enabled parser (CBool 0)) + Nothing <$ liftIO (TS.ts_parser_set_enabled parser (CBool 0) >> wait parsing) toAST :: forall grammar . (Bounded grammar, Enum grammar) => TS.Node -> IO (Base (AST [] grammar) TS.Node) From 7b9ca2a0b09fb160089c80e1dcfe7f5f3ae29c09 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Tue, 5 Feb 2019 10:43:16 -0800 Subject: [PATCH 2/3] Split over two lines --- src/Parsing/TreeSitter.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Parsing/TreeSitter.hs b/src/Parsing/TreeSitter.hs index 4a25fdd1b..d85e981f0 100644 --- a/src/Parsing/TreeSitter.hs +++ b/src/Parsing/TreeSitter.hs @@ -85,7 +85,8 @@ parseToAST parseTimeout language Blob{..} = bracket (liftIO TS.ts_parser_new) (l Just (Succeeded ast) -> Just ast <$ trace ("tree-sitter: parsing succeeded " <> blobPath) Nothing -> do trace $ "tree-sitter: parsing timed out " <> blobPath - Nothing <$ liftIO (TS.ts_parser_set_enabled parser (CBool 0) >> wait parsing) + _ <- liftIO $ TS.ts_parser_set_enabled parser (CBool 0) + Nothing <$ liftIO (wait parsing) toAST :: forall grammar . (Bounded grammar, Enum grammar) => TS.Node -> IO (Base (AST [] grammar) TS.Node) From 8f57b5d08bca9bb777f1eca0688f80e54edb5eab Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Tue, 5 Feb 2019 13:56:55 -0800 Subject: [PATCH 3/3] Don't need `_ <-` pattern --- src/Parsing/TreeSitter.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Parsing/TreeSitter.hs b/src/Parsing/TreeSitter.hs index d85e981f0..15ca8a920 100644 --- a/src/Parsing/TreeSitter.hs +++ b/src/Parsing/TreeSitter.hs @@ -85,7 +85,7 @@ parseToAST parseTimeout language Blob{..} = bracket (liftIO TS.ts_parser_new) (l Just (Succeeded ast) -> Just ast <$ trace ("tree-sitter: parsing succeeded " <> blobPath) Nothing -> do trace $ "tree-sitter: parsing timed out " <> blobPath - _ <- liftIO $ TS.ts_parser_set_enabled parser (CBool 0) + liftIO (TS.ts_parser_set_enabled parser (CBool 0)) Nothing <$ liftIO (wait parsing)