Repository navigation
Fix parallel render() temp file deletion (#1632) - #2631
Merged
Merged
Conversation
as_tmpfile() writes rmarkdown-str*.html files that Pandoc reads later
during conversion (navbar, in-header/before-body/after-body includes).
On render() exit, clean_tmpfiles() removed every file matching that
pattern in tempdir(). Forked parallel workers share the parent's
tempdir(), so one worker's cleanup deleted sibling workers' files while
Pandoc was still using them, producing:
pandoc: /tmp/.../rmarkdown-str<hex>.html: openBinaryFile: does not
exist (No such file or directory)
This is why makePSOCKcluster (separate tempdir per process) worked while
makeForkCluster did not.
Track the files created by as_tmpfile() in .globals$tmpfiles and unlink
only those, so each process cleans up exactly what it created. tempfile()
already generates per-process unique names, so no cross-process name
collision remains.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
render()in parallel via a fork cluster (makeForkCluster,registerDoParallel(cores>1),foreach %dopar%,BiocParallel::MulticoreParam) intermittently fails with:makePSOCKclusternever hit this — the tell.Root cause
as_tmpfile()writesrmarkdown-str*.htmlfiles that Pandoc reads later during conversion (navbar,in_header/before_body/after_bodyincludes). Onrender()exit,clean_tmpfiles()deleted every file matching that pattern intempdir():Forked workers share the parent's
tempdir(), so one worker's cleanup deleted sibling workers' files while Pandoc was still using them. PSOCK workers get a separatetempdir()per process, hence no failure.Diagnosed by @gorgitko in #1632 back in 2019; the long-standing workaround was stubbing out
clean_tmpfilesviaassignInNamespace().Fix
Track files created by
as_tmpfile()in.globals$tmpfilesand unlink only those. Each process cleans up exactly what it created; siblings are untouched.tempfile()already generates per-process unique names (verified: 3200 names across 16 forks, 0 collisions), so no cross-process name collision remains.Test
Added a regression test in
test-utils.R: a stray file matching the old glob pattern survivesclean_tmpfiles(), while the process's own registered file is removed.Scope
Fixes the parallel-render cause. The parallel-render reports in #1268 share this root cause; the network/UNC-drive cause in #1268 is separate and remains open.