Skip to content

Commit 6d84a37

Browse files
committed
prevent package_callbacks to run multiple time for a single package (#54243)
Introduced in #52841. (cherry picked from commit b385b4f)
1 parent d5237bf commit 6d84a37

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

base/loading.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,7 @@ function __require_prelocked(uuidkey::PkgId, env=nothing)
22242224
run_package_callbacks(uuidkey)
22252225
else
22262226
m = get(loaded_modules, uuidkey, nothing)
2227-
if m !== nothing
2227+
if m !== nothing && !haskey(explicit_loaded_modules, uuidkey)
22282228
explicit_loaded_modules[uuidkey] = m
22292229
run_package_callbacks(uuidkey)
22302230
end

test/precompile.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,25 @@ precompile_test_harness("package_callbacks") do dir
13631363
finally
13641364
pop!(Base.package_callbacks)
13651365
end
1366+
Test5_module = :Teste4095a85
1367+
write(joinpath(dir, "$(Test5_module).jl"),
1368+
"""
1369+
module $(Test5_module)
1370+
end
1371+
""")
1372+
Base.compilecache(Base.PkgId("$(Test5_module)"))
1373+
cnt = 0
1374+
push!(Base.package_callbacks, _->(cnt += 1))
1375+
try
1376+
@eval using $(Symbol(Test5_module))
1377+
@eval using $(Symbol(Test5_module))
1378+
@eval using $(Symbol(Test5_module))
1379+
@eval using $(Symbol(Test5_module))
1380+
@eval using $(Symbol(Test5_module))
1381+
@test cnt == 1
1382+
finally
1383+
pop!(Base.package_callbacks)
1384+
end
13661385
end
13671386

13681387
# Issue #19960

0 commit comments

Comments
 (0)