-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
RFC: Don't leave precompile-time tempdirs to be cleaned-up in binaries (#60078) #60106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Don't leave precompile-time tempdirs to be cleaned-up in binaries (#60078) #60106
Conversation
|
Please use a descriptive title rather than "Fix issue", that greatly aids in discover ability |
|
Seems like a better solution would be a manual |
In my understanding, these temp files are removed because they are created in a temp dir created by the call to |
We attempt to explicitly do this automatically, but we forgot to call |
|
This might not be the ideal fix (figuring out how to run the right atexit hooks), but it appears to be all of sufficient, correct, and minimal, so I've gone ahead and merged it and marked for backporting to all affected versions (this bug does not appear to be present in v1.10) |
When starting julia, `Base.Filesystem.TEMP_CLEANUP` should be empty, but is being left with these two files. The proposed fix is to set up temporary files created by function `generate_precompile_statements` in `contrib/generate_precompile.jl` to have no automatic cleanup. This won't do harm since they will be removed by the cleanup of the temporary directory created by the call to `mktempdir` in function `generate_precompile_statements` (see the call `rm(tmpdir, recursive=true)` in `base/file.jl`). These should be removed by the atexit hook, but we didn't run `Base.__init__` or `Base.Filesystem.__postinit__` hooks to re-register this cleanup handler in the sys.so generation process (only in sysbase.so). To test this issue, one can do: `$ mkdir $TMPDIR/JuliaBuild` `$ OLDTMPDIR=$TMPDIR` `$ export TMPDIR=$TMPDIR/JuliaBuild` `$ cd <julia's build root>` `$ <build julia>` `$ strings usr/lib/julia/sys.dylib|less # shows that the temp. dir. JuliaBuild is hardcoded in the binaries` `$ TMPDIR=$OLDTMPDIR` `$ chmod u-x $TMPDIR/JuliaBuild` `$ <run the built julia with ./julia and exit> # should try to use $TMPDIR/JuliaBuild which is now inaccessible` Without the fix, the last step triggers the infinite loop of ``Failed to clean up temporary path''. With the fix, one can see that the binaries (`usr/lib/julia/sys.dylib`) do not contain the temp. dir. anymore, and the infinite loop of errors is not triggered. Or simply by observing that `./julia -E 'Base.Filesystem.TEMP_CLEANUP'` is not empty. Fix #60078 (cherry picked from commit 1eea4b6)
When starting julia, `Base.Filesystem.TEMP_CLEANUP` should be empty, but is being left with these two files. The proposed fix is to set up temporary files created by function `generate_precompile_statements` in `contrib/generate_precompile.jl` to have no automatic cleanup. This won't do harm since they will be removed by the cleanup of the temporary directory created by the call to `mktempdir` in function `generate_precompile_statements` (see the call `rm(tmpdir, recursive=true)` in `base/file.jl`). These should be removed by the atexit hook, but we didn't run `Base.__init__` or `Base.Filesystem.__postinit__` hooks to re-register this cleanup handler in the sys.so generation process (only in sysbase.so). To test this issue, one can do: `$ mkdir $TMPDIR/JuliaBuild` `$ OLDTMPDIR=$TMPDIR` `$ export TMPDIR=$TMPDIR/JuliaBuild` `$ cd <julia's build root>` `$ <build julia>` `$ strings usr/lib/julia/sys.dylib|less # shows that the temp. dir. JuliaBuild is hardcoded in the binaries` `$ TMPDIR=$OLDTMPDIR` `$ chmod u-x $TMPDIR/JuliaBuild` `$ <run the built julia with ./julia and exit> # should try to use $TMPDIR/JuliaBuild which is now inaccessible` Without the fix, the last step triggers the infinite loop of ``Failed to clean up temporary path''. With the fix, one can see that the binaries (`usr/lib/julia/sys.dylib`) do not contain the temp. dir. anymore, and the infinite loop of errors is not triggered. Or simply by observing that `./julia -E 'Base.Filesystem.TEMP_CLEANUP'` is not empty. Fix #60078 (cherry picked from commit 1eea4b6)
I think that #60078 is due to the fact that Julia binaries inherit the dictionary
TEMP_CLEANUP(used inbase/file.jl) defined during build (more precisely, by functiongenerate_precompile_statementsincontrib/generate_precompile.jl), which is wrong because the temporary files and directories at runtime may reside in quite a different directory than at build time.In particular, in the case of MacPorts on a recent Mac OS (e.g. Mac OS 15), where each user has a specific tempdir not accessible to others, building Julia is performed by the user
macports, then Julia's binary hardcodes that some directories inside the tempdir of usermacportshave to be cleaned on exit. When running Julia under the identity of another user, who has another tempdir and no read/write access to the tempdir ofmacports, the reported failure happens.The proposed fix is to set up temporary files created by function
generate_precompile_statementsincontrib/generate_precompile.jlto have no automatic cleanup. This won't do harm since they will be removed by the cleanup of the temporary directory created by the call tomktempdirin functiongenerate_precompile_statements(see the callrm(tmpdir, recursive=true)inbase/file.jl). On the other hand, the benefit of this is that the dictionaryTEMP_CLEANUPat runtime will be free of irrelevant compile-time directories to clean.To test this issue, one can do:
$ mkdir $TMPDIR/JuliaBuild$ OLDTMPDIR=$TMPDIR$ export TMPDIR=$TMPDIR/JuliaBuild$ cd <julia's build root>$ <build julia>$ strings usr/lib/julia/sys.dylib|less # shows that the temp. dir. JuliaBuild is hardcoded in the binaries$ TMPDIR=$OLDTMPDIR$ chmod u-x $TMPDIR/JuliaBuild$ <run the built julia with ./julia and exit> # should try to use $TMPDIR/JuliaBuild which is now inaccessibleWithout the fix, the last step triggers the infinite loop of ``Failed to clean up temporary path''. With the fix, one can see that the binaries (
usr/lib/julia/sys.dylib) do not contain the temp. dir. anymore, and the infinite loop of errors is not triggered.Any comment/help appreciated.