Redirect stdout
to devnull
during precompilation
#231
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Calling
redirect_stdout
without any arguments redirects the output to a newly createdPipe
1 (which is mostly a wrapper around standard *nix pipes). Not reading data from thisPipe
can result in precompilation to hang, e.g. in CI environments such as GitHub Actions (as was the case for me) or as reported here2.This is due to a fundamental expectation that a (*nix) kernel has on pipes, as documented3, "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 todevnull
circumvents this expectation and ensures precompilation succeeds.I was able to verify the bug and the fix due to our (internal) CI systems getting stuck and trying with and without the fix (a couple of times to ensure the test was reliable/reproducible). Unfortunately, I don't have any publicly available logs to show as I couldn't get this reproduced on standard GitHub Actions runners. Likely because these always start with a fresh Julia depot and it appears that every time this becomes an issue some problem with the depot seems to trigger it.
Thanks to @vtjnash for pointing me in the right direction.
Footnotes
https://github.com/JuliaLang/julia/blob/9233a16172139c06107b475480bfce098f10a8a6/base/stream.jl#L1259 ↩
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 ↩
https://man7.org/linux/man-pages/man7/pipe.7.html ↩