Skip to content

Commit f555b4b

Browse files
Tweak cache pidlocking (#50214)
1 parent 90521dd commit f555b4b

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

base/loading.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,11 +2819,20 @@ global mkpidlock_hook
28192819
global trymkpidlock_hook
28202820
global parse_pidfile_hook
28212821

2822-
# allows processes to wait if another process is precompiling a given source already
2823-
function maybe_cachefile_lock(f, pkg::PkgId, srcpath::String)
2822+
# The preferences hash is only known after precompilation so just assume no preferences
2823+
# meaning that if all other conditions are equal, the same package cannot be precompiled
2824+
# with different preferences at the same time.
2825+
compilecache_pidfile_path(pkg::PkgId) = compilecache_path(pkg, UInt64(0)) * ".pidfile"
2826+
2827+
# Allows processes to wait if another process is precompiling a given source already.
2828+
# The lock file is deleted and precompilation will proceed after `stale_age` seconds if
2829+
# - the locking process no longer exists
2830+
# - the lock is held by another host, since processes cannot be checked remotely
2831+
# or after `stale_age * 25` seconds if it does still exist.
2832+
function maybe_cachefile_lock(f, pkg::PkgId, srcpath::String; stale_age=60)
28242833
if @isdefined(mkpidlock_hook) && @isdefined(trymkpidlock_hook) && @isdefined(parse_pidfile_hook)
2825-
pidfile = string(srcpath, ".pidlock")
2826-
cachefile = invokelatest(trymkpidlock_hook, f, pidfile)
2834+
pidfile = compilecache_pidfile_path(pkg)
2835+
cachefile = invokelatest(trymkpidlock_hook, f, pidfile; stale_age)
28272836
if cachefile === false
28282837
pid, hostname, age = invokelatest(parse_pidfile_hook, pidfile)
28292838
verbosity = isinteractive() ? CoreLogging.Info : CoreLogging.Debug
@@ -2834,7 +2843,7 @@ function maybe_cachefile_lock(f, pkg::PkgId, srcpath::String)
28342843
end
28352844
# wait until the lock is available, but don't actually acquire it
28362845
# returning nothing indicates a process waited for another
2837-
return invokelatest(mkpidlock_hook, Returns(nothing), pidfile)
2846+
return invokelatest(mkpidlock_hook, Returns(nothing), pidfile; stale_age)
28382847
end
28392848
return cachefile
28402849
else

0 commit comments

Comments
 (0)