forester hangs on some forests #18

Closed kento.tngl.sh
Closed opened by and assigned to kento.tngl.sh

Previously this ticket referred to --emit-legacy-xml, but in fact Forester (both LSP and build) hangs on my laptop with my forest.

Running in verbose mode, the last thing that it appears to do is plant all the articles. This has the feeling of a deadlock in the renderer.

This doesn't seem to have been introduced recently; it happens only on my laptop (Apple M2 processor), and not (that I've seen so far) on my desktop (Apple M4).

It appears that if I remove the State.submit around Asset_router.install in the evaluator, this solves this particular deadlock:

diff --git a/lib/compiler/Eval.ml b/lib/compiler/Eval.ml
index 32b9255..946bc28 100644
--- a/lib/compiler/Eval.ml
+++ b/lib/compiler/Eval.ml
@@ -492,9 +492,9 @@ and eval_node ~env ({value; range} as node) : (Value.t, Eval_error.t) result =
       pop_text_arg_loc ~env ~range
     in
     begin match
-      State.submit ~forest:env.forest (fun () ->
+      (* State.submit ~forest:env.forest (fun () -> *)
           Asset_router.install ~env:env.forest.env ~config:env.forest.config
-            ~range:path_range ~source_path ())
+            ~range:path_range ~source_path ()
     with
     | Ok (uri, Some content) ->
       begin

(This was suggested by ChatGPT, and I tried it out.) But I am a little worried in general and would like to better understand why this was submitted to the executor pool.

This is because asset hashing is among the most expensive things that forester does. I don't get why this would fix a deadlock though. I have encountered similar issues in the past, but the fixes involved some mutex that was locking access to a domain-unsafe data structure.

Hm, I suppose there is actually no reason to submit to the executor pool here, since we need to await the hash result to proceed anyway. BTW, hashing is now done in the eval routine so we can avoid unnecessarily hashing assets that are never referred to.

I'll remove this call to State.submit

I think the call may be concerning if it causes re-entrancy... The evaluator might be called from inside a locked routine, and if this thing has to acquire the lock... But I don't understand the code very well so it is hard for me to say.

This comment was deleted.
Sign up or Sign in to add to the discussion.