Skip to content

Commit 3b34a57

Browse files
author
José Valim
committed
Avoid race conditions in the struct detection
1 parent 62a469d commit 3b34a57

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/elixir/lib/kernel/error_handler.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ defmodule Kernel.ErrorHandler do
2929
{:error, _} ->
3030
parent = :erlang.get(:elixir_compiler_pid)
3131
ref = :erlang.make_ref
32-
send parent, {:waiting, module, self(), ref, module}
32+
send parent, {:waiting, :module, self(), ref, module}
3333
:erlang.garbage_collect(self)
3434
receive do
3535
{^ref, :ready} -> :ok

lib/elixir/src/elixir_map.erl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ load_struct(Meta, Name, S) ->
8282
Context = lists:keyfind(struct, 1, Meta) == {struct, context},
8383

8484
Local =
85-
elixir_module:is_open(Name) andalso
85+
not(ensure_loaded(Name)) andalso
8686
(Context orelse wait_for_struct(Name)),
8787

8888
try
@@ -112,6 +112,12 @@ load_struct(Meta, Name, S) ->
112112
end
113113
end.
114114

115+
ensure_loaded(Module) ->
116+
case code:ensure_loaded(Module) of
117+
{module, Module} -> true;
118+
{error, _} -> false
119+
end.
120+
115121
wait_for_struct(Module) ->
116122
case erlang:get(elixir_compiler_pid) of
117123
undefined ->

0 commit comments

Comments
 (0)