From 8cf53ff48671b7ba5b821e5e2243b21d65959c08 Mon Sep 17 00:00:00 2001 From: Joris Kraak Date: Tue, 28 Nov 2023 01:32:02 +0100 Subject: [PATCH] :bug: Redirect `stdout` to `devnull` during precompilation (#231) Calling `redirect_stdout` without any arguments redirects the output to a newly created `Pipe`[^1] (which is mostly a wrapper around standard *nix pipes). Not reading data from this `Pipe` can result in precompilation to hang, e.g. in CI environments such as GitHub Actions or as reported here[^2]. This is due to a fundamental expectation that a (*nix) kernel has on pipes, as documented[^3] "write will block until sufficient data has been read from the pipe to allow the write to complete". For this reason never reading from `new_stdout` may cause the precompilation to hang. Explicitly redirecting to `devnull` circumvents this expectation and ensures precompilation succeeds. [^1]: https://github.com/JuliaLang/julia/blob/9233a16172139c06107b475480bfce098f10a8a6/base/stream.jl#L1259 [^2]: https://discourse.julialang.org/t/when-i-add-any-package-prettytables-will-get-stuck-here-and-cannot-be-executed-i-need-to-control-c-to-close-it [^3]: https://man7.org/linux/man-pages/man7/pipe.7.html --- src/precompilation.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/precompilation.jl b/src/precompilation.jl index df4cf002..88697853 100644 --- a/src/precompilation.jl +++ b/src/precompilation.jl @@ -68,7 +68,7 @@ PrecompileTools.@setup_workload begin # We will redirect the `stdout` and `stdin` so that we can execute the pager and input # some commands without making visible changes to the user. old_stdout = Base.stdout - new_stdout = redirect_stdout() + new_stdout = redirect_stdout(devnull) # In HTML, we use `display` if we are rendering to `stdout`. However, even if we are # redirecting it, the text is still begin shown in the display. Thus, we create a buffer