Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix deadlock in code loading #28416

Merged
merged 1 commit into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ end
# or an Exception that describes why it couldn't be loaded
# and it reconnects the Base.Docs.META
function _include_from_serialized(path::String, depmods::Vector{Any})
restored = ccall(:jl_restore_incremental, Any, (Cstring, Any), path, depmods)
sv = ccall(:jl_restore_incremental, Any, (Cstring, Any), path, depmods)
restored = sv[1]
Copy link
Member

@KristofferC KristofferC Aug 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Keno, this looks incorrect. The return value from jl_restore_incremental is not indexable in case the return value is an exception?

Copy link
Member Author

@Keno Keno Aug 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This same commit changed the regular return value to be a tuple, but you are correct that something got messed up with the other return path in this function. Wanna fix it and ideally at a test case ;)?

if !isa(restored, Exception)
for M in restored::Vector{Any}
M = M::Module
Expand All @@ -623,6 +624,7 @@ function _include_from_serialized(path::String, depmods::Vector{Any})
end
end
end
isassigned(sv, 2) && ccall(:jl_init_restored_modules, Cvoid, (Any,), sv[2])
return restored
end

Expand Down
6 changes: 3 additions & 3 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ static jl_array_t *jl_finalize_deserializer(jl_serializer_state *s, arraylist_t
return init_order;
}

static void jl_init_restored_modules(jl_array_t *init_order)
JL_DLLEXPORT void jl_init_restored_modules(jl_array_t *init_order)
{
if (!init_order)
return;
Expand Down Expand Up @@ -3118,10 +3118,10 @@ static jl_value_t *_jl_restore_incremental(ios_t *f, jl_array_t *mod_array)
arraylist_free(tracee_list);
free(tracee_list);
}
jl_init_restored_modules(init_order);
jl_value_t *ret = (jl_value_t*)jl_svec(2, restored, init_order);
JL_GC_POP();

return (jl_value_t*)restored;
return (jl_value_t*)ret;
}

JL_DLLEXPORT jl_value_t *jl_restore_incremental_from_buf(const char *buf, size_t sz, jl_array_t *mod_array)
Expand Down
37 changes: 37 additions & 0 deletions test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,41 @@ let
end
end

let
load_path = mktempdir()
load_cache_path = mktempdir()
try
write(joinpath(load_path, "Foo26028.jl"),
"""
module Foo26028

module Bar26028
x = 0
end

function __init__()
include(joinpath(@__DIR__, "Baz26028.jl"))
end

end
""")
write(joinpath(load_path, "Baz26028.jl"),
"""
module Baz26028
import Foo26028.Bar26028.x
end
""")

pushfirst!(LOAD_PATH, load_path)
pushfirst!(DEPOT_PATH, load_cache_path)

Base.compilecache(Base.PkgId("Foo26028"))
@test_nowarn @eval using Foo26028
finally
rm(load_path, recursive=true)
rm(load_cache_path, recursive=true)
end
end


end # !withenv