Skip to content

Commit 4ed8814

Browse files
authored
gracefully fall back to non pid locked precompilation if FileWatching is not loaded (#56570)
Fixes #56569
1 parent b660649 commit 4ed8814

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

base/loading.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3839,9 +3839,9 @@ const compilecache_pidlock_stale_age = 10
38393839
function maybe_cachefile_lock(f, pkg::PkgId, srcpath::String; stale_age=compilecache_pidlock_stale_age)
38403840
if @isdefined(mkpidlock_hook) && @isdefined(trymkpidlock_hook) && @isdefined(parse_pidfile_hook)
38413841
pidfile = compilecache_pidfile_path(pkg)
3842-
cachefile = invokelatest(trymkpidlock_hook, f, pidfile; stale_age)
3842+
cachefile = @invokelatest trymkpidlock_hook(f, pidfile; stale_age)
38433843
if cachefile === false
3844-
pid, hostname, age = invokelatest(parse_pidfile_hook, pidfile)
3844+
pid, hostname, age = @invokelatest parse_pidfile_hook(pidfile)
38453845
verbosity = isinteractive() ? CoreLogging.Info : CoreLogging.Debug
38463846
if isempty(hostname) || hostname == gethostname()
38473847
@logmsg verbosity "Waiting for another process (pid: $pid) to finish precompiling $(repr("text/plain", pkg)). Pidfile: $pidfile"
@@ -3850,7 +3850,7 @@ function maybe_cachefile_lock(f, pkg::PkgId, srcpath::String; stale_age=compilec
38503850
end
38513851
# wait until the lock is available, but don't actually acquire it
38523852
# returning nothing indicates a process waited for another
3853-
return invokelatest(mkpidlock_hook, Returns(nothing), pidfile; stale_age)
3853+
return @invokelatest mkpidlock_hook(Returns(nothing), pidfile; stale_age)
38543854
end
38553855
return cachefile
38563856
else

base/precompilation.jl

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Precompilation
22

33
using Base: PkgId, UUID, SHA1, parsed_toml, project_file_name_uuid, project_names,
44
project_file_manifest_path, get_deps, preferences_names, isaccessibledir, isfile_casesensitive,
5-
base_project
5+
base_project, isdefined
66

77
# This is currently only used for pkgprecompile but the plan is to use this in code loading in the future
88
# see the `kc/codeloading2.0` branch
@@ -1031,14 +1031,16 @@ end
10311031

10321032
# Can be merged with `maybe_cachefile_lock` in loading?
10331033
function precompile_pkgs_maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLock, fancyprint::Bool, pkg_config, pkgspidlocked, hascolor)
1034+
if !(isdefined(Base, :mkpidlock_hook) && isdefined(Base, :trymkpidlock_hook) && Base.isdefined(Base, :parse_pidfile_hook))
1035+
return f()
1036+
end
10341037
pkg, config = pkg_config
10351038
flags, cacheflags = config
1036-
FileWatching = Base.loaded_modules[Base.PkgId(Base.UUID("7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"), "FileWatching")]
10371039
stale_age = Base.compilecache_pidlock_stale_age
10381040
pidfile = Base.compilecache_pidfile_path(pkg, flags=cacheflags)
1039-
cachefile = FileWatching.trymkpidlock(f, pidfile; stale_age)
1041+
cachefile = @invokelatest Base.trymkpidlock_hook(f, pidfile; stale_age)
10401042
if cachefile === false
1041-
pid, hostname, age = FileWatching.Pidfile.parse_pidfile(pidfile)
1043+
pid, hostname, age = @invokelatest Base.parse_pidfile_hook(pidfile)
10421044
pkgspidlocked[pkg_config] = if isempty(hostname) || hostname == gethostname()
10431045
if pid == getpid()
10441046
"an async task in this process (pidfile: $pidfile)"
@@ -1052,15 +1054,16 @@ function precompile_pkgs_maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLo
10521054
println(io, " ", pkg.name, _color_string(" Being precompiled by $(pkgspidlocked[pkg_config])", Base.info_color(), hascolor))
10531055
end
10541056
# wait until the lock is available
1055-
FileWatching.mkpidlock(pidfile; stale_age) do
1056-
# double-check in case the other process crashed or the lock expired
1057-
if Base.isprecompiled(pkg; ignore_loaded=true, flags=cacheflags) # don't use caches for this as the env state will have changed
1058-
return nothing # returning nothing indicates a process waited for another
1059-
else
1060-
delete!(pkgspidlocked, pkg_config)
1061-
return f() # precompile
1062-
end
1063-
end
1057+
@invokelatest Base.mkpidlock_hook(() -> begin
1058+
# double-check in case the other process crashed or the lock expired
1059+
if Base.isprecompiled(pkg; ignore_loaded=true, flags=cacheflags) # don't use caches for this as the env state will have changed
1060+
return nothing # returning nothing indicates a process waited for another
1061+
else
1062+
delete!(pkgspidlocked, pkg_config)
1063+
return f() # precompile
1064+
end
1065+
end,
1066+
pidfile; stale_age)
10641067
end
10651068
return cachefile
10661069
end

0 commit comments

Comments
 (0)