Skip to content

Commit e78a342

Browse files
committed
fixup! fix concurrent module loading return value
1 parent 9d7d27b commit e78a342

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

base/loading.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,28 +2460,27 @@ function _require(pkg::PkgId, env=nothing)
24602460
end
24612461
# spawn off a new incremental pre-compile task for recursive `require` calls
24622462
loaded = maybe_cachefile_lock(pkg, path) do
2463-
# double-check now that we have lock
2463+
# double-check the search now that we have lock
24642464
m = _require_search_from_serialized(pkg, path, UInt128(0), true)
24652465
m isa Module && return m
24662466
return compilecache(pkg, path; reasons)
24672467
end
24682468
loaded isa Module && return loaded
2469-
cachefile = loaded
2470-
if isnothing(cachefile) # maybe_cachefile_lock returns nothing if it had to wait for another process
2469+
if isnothing(loaded) # maybe_cachefile_lock returns nothing if it had to wait for another process
24712470
@goto load_from_cache # the new cachefile will have the newest mtime so will come first in the search
2472-
elseif isa(cachefile, Exception)
2473-
if precompilableerror(cachefile)
2471+
elseif isa(loaded, Exception)
2472+
if precompilableerror(loaded)
24742473
verbosity = isinteractive() ? CoreLogging.Info : CoreLogging.Debug
2475-
@logmsg verbosity "Skipping precompilation due to precompilable error. Importing $(repr("text/plain", pkg))." exception=m
2474+
@logmsg verbosity "Skipping precompilation due to precompilable error. Importing $(repr("text/plain", pkg))." exception=loaded
24762475
else
2477-
@warn "The call to compilecache failed to create a usable precompiled cache file for $(repr("text/plain", pkg))" exception=m
2476+
@warn "The call to compilecache failed to create a usable precompiled cache file for $(repr("text/plain", pkg))" exception=loaded
24782477
end
24792478
# fall-through to loading the file locally if not incremental
24802479
else
2481-
cachefile, ocachefile = cachefile::Tuple{String, Union{Nothing, String}}
2480+
cachefile, ocachefile = loaded::Tuple{String, Union{Nothing, String}}
24822481
loaded = _tryrequire_from_serialized(pkg, cachefile, ocachefile)
24832482
if !isa(loaded, Module)
2484-
@warn "The call to compilecache failed to create a usable precompiled cache file for $(repr("text/plain", pkg))" exception=m
2483+
@warn "The call to compilecache failed to create a usable precompiled cache file for $(repr("text/plain", pkg))" exception=loaded
24852484
else
24862485
return loaded
24872486
end

test/loading.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,11 @@ end
12101210
empty!(Base.DEPOT_PATH)
12111211
append!(Base.DEPOT_PATH, original_depot_path)
12121212

1213+
module loaded_pkgid1 end
1214+
module loaded_pkgid2 end
1215+
module loaded_pkgid3 end
1216+
module loaded_pkgid4 end
1217+
12131218
@testset "loading deadlock detector" begin
12141219
pkid1 = Base.PkgId("pkgid1")
12151220
pkid2 = Base.PkgId("pkgid2")
@@ -1221,25 +1226,25 @@ append!(Base.DEPOT_PATH, original_depot_path)
12211226
t1 = @async begin
12221227
@test nothing === @lock Base.require_lock Base.start_loading(pkid2) # @async module pkgid2; using pkgid1; end
12231228
notify(e)
1224-
@test "loaded_pkgid1" == @lock Base.require_lock Base.start_loading(pkid1)
1225-
@lock Base.require_lock Base.end_loading(pkid2, "loaded_pkgid2")
1229+
@test loaded_pkgid1 == @lock Base.require_lock Base.start_loading(pkid1)
1230+
@lock Base.require_lock Base.end_loading(pkid2, loaded_pkgid2)
12261231
end
12271232
wait(e)
12281233
reset(e)
12291234
t2 = @async begin
12301235
@test nothing === @lock Base.require_lock Base.start_loading(pkid3) # @async module pkgid3; using pkgid2; end
12311236
notify(e)
1232-
@test "loaded_pkgid2" == @lock Base.require_lock Base.start_loading(pkid2)
1233-
@lock Base.require_lock Base.end_loading(pkid3, "loaded_pkgid3")
1237+
@test loaded_pkgid2 == @lock Base.require_lock Base.start_loading(pkid2)
1238+
@lock Base.require_lock Base.end_loading(pkid3, loaded_pkgid3)
12341239
end
12351240
wait(e)
12361241
reset(e)
12371242
@test_throws(ConcurrencyViolationError("deadlock detected in loading pkgid3 -> pkgid2 -> pkgid1 -> pkgid3 && pkgid4"),
12381243
@lock Base.require_lock Base.start_loading(pkid3)).value # try using pkgid3
12391244
@test_throws(ConcurrencyViolationError("deadlock detected in loading pkgid4 -> pkgid4 && pkgid1"),
12401245
@lock Base.require_lock Base.start_loading(pkid4)).value # try using pkgid4
1241-
@lock Base.require_lock Base.end_loading(pkid1, "loaded_pkgid1") # end
1242-
@lock Base.require_lock Base.end_loading(pkid4, "loaded_pkgid4") # end
1246+
@lock Base.require_lock Base.end_loading(pkid1, loaded_pkgid1) # end
1247+
@lock Base.require_lock Base.end_loading(pkid4, loaded_pkgid4) # end
12431248
wait(t2)
12441249
wait(t1)
12451250
end

0 commit comments

Comments
 (0)