Skip to content

Commit 22b71d0

Browse files
committed
loading: improve circular using error message clarity
1 parent 2a168ee commit 22b71d0

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

base/loading.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,6 @@ function canstart_loading(modkey::PkgId, build_id::UInt128, stalecheck::Bool)
21782178
# load already in progress for this module on the task
21792179
task, cond = loading
21802180
deps = String[modkey.name]
2181-
pkgid = modkey
21822181
assert_havelock(cond.lock)
21832182
if debug_loading_deadlocks && current_task() !== task
21842183
waiters = Dict{Task,Pair{Task,PkgId}}() # invert to track waiting tasks => loading tasks
@@ -2198,18 +2197,26 @@ function canstart_loading(modkey::PkgId, build_id::UInt128, stalecheck::Bool)
21982197
end
21992198
end
22002199
if current_task() === task
2201-
others = String[modkey.name] # repeat this to emphasize the cycle here
2200+
push!(deps, modkey.name) # repeat this to emphasize the cycle here
2201+
others = Set{String}()
22022202
for each in package_locks # list the rest of the packages being loaded too
22032203
if each[2][1] === task
22042204
other = each[1].name
2205-
other == modkey.name || other == pkgid.name || push!(others, other)
2205+
other == modkey.name || push!(others, other)
22062206
end
22072207
end
2208+
# remove duplicates from others already in deps
2209+
for dep in deps
2210+
delete!(others, dep)
2211+
end
22082212
msg = sprint(deps, others) do io, deps, others
22092213
print(io, "deadlock detected in loading ")
2210-
join(io, deps, " -> ")
2211-
print(io, " -> ")
2212-
join(io, others, " && ")
2214+
join(io, deps, " using ")
2215+
if !isempty(others)
2216+
print(io, " (while loading ")
2217+
join(io, others, " and ")
2218+
print(io, ")")
2219+
end
22132220
end
22142221
throw(ConcurrencyViolationError(msg))
22152222
end

test/loading.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,9 +1345,9 @@ module loaded_pkgid4 end
13451345
end
13461346
wait(e)
13471347
reset(e)
1348-
@test_throws(ConcurrencyViolationError("deadlock detected in loading pkgid3 -> pkgid2 -> pkgid1 -> pkgid3 && pkgid4"),
1348+
@test_throws(ConcurrencyViolationError("deadlock detected in loading pkgid3 using pkgid2 using pkgid1 using pkgid3 (while loading pkgid4)"),
13491349
@lock Base.require_lock Base.start_loading(pkid3, build_id, false)).value # try using pkgid3
1350-
@test_throws(ConcurrencyViolationError("deadlock detected in loading pkgid4 -> pkgid4 && pkgid1"),
1350+
@test_throws(ConcurrencyViolationError("deadlock detected in loading pkgid4 using pkgid4 (while loading pkgid1)"),
13511351
@lock Base.require_lock Base.start_loading(pkid4, build_id, false)).value # try using pkgid4
13521352
@lock Base.require_lock Base.end_loading(pkid1, loaded_pkgid1) # end
13531353
@lock Base.require_lock Base.end_loading(pkid4, loaded_pkgid4) # end

test/precompile.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ precompile_test_harness("Issue #26028") do load_path
16071607
"""
16081608
module Baz26028
16091609
using Test
1610-
@test_throws(ConcurrencyViolationError("deadlock detected in loading Foo26028 -> Foo26028"),
1610+
@test_throws(ConcurrencyViolationError("deadlock detected in loading Foo26028 using Foo26028"),
16111611
@eval import Foo26028.Bar26028.x)
16121612
import ..Foo26028.Bar26028.y
16131613
end

0 commit comments

Comments
 (0)