Skip to content

Commit

Permalink
🐛 Redirect stdout to devnull during precompilation (#231)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bauglir authored Nov 28, 2023
1 parent b9decd1 commit 8cf53ff
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/precompilation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

2 comments on commit 8cf53ff

@sathvikbhagavan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ronisbr, can you cut a patch release with this fix?

@ronisbr
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure! I will do this today.

Please sign in to comment.