Skip to content

Commit

Permalink
Better solve deadlocks on Elixir v1.12+ (#1057)
Browse files Browse the repository at this point in the history
* Better solve deadlocks on Elixir v1.12+

Closes #937.

* Update type_imports.ex

* Silence dialyzer error

Co-authored-by: José Valim <jose.valim@plataformatec.com.br>
  • Loading branch information
binaryseed and José Valim authored Mar 26, 2021
1 parent 1e219c6 commit 659d15d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/absinthe/phase/schema/type_imports.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Absinthe.Phase.Schema.TypeImports do
end

defp do_imports([{module, opts} | rest], acc, schema) do
case Code.ensure_compiled(module) do
case ensure_compiled(module) do
{:module, module} ->
[other_def] = module.__absinthe_blueprint__.schema_definitions

Expand All @@ -58,6 +58,21 @@ defmodule Absinthe.Phase.Schema.TypeImports do
end
end

# Elixir v1.12 includes a Code.ensure_compiled!/1 that tells
# the compiler it should only continue if the module is available.
# This gives the Elixir compiler more information to address
# deadlocks.
# TODO: Remove the else clause once we require Elixir v1.12+.
@compile {:no_warn_undefined, {Code, :ensure_compiled!, 1}}
@dialyzer {:nowarn_function, [ensure_compiled: 1]}
defp ensure_compiled(module) do
if function_exported?(Code, :ensure_compiled!, 1) do
{:module, Code.ensure_compiled!(module)}
else
Code.ensure_compiled(module)
end
end

# Generate an error when loading module fails
@spec error(module :: module(), error :: :embedded | :badfile | :nofile | :on_load_failure) ::
Absinthe.Phase.Error.t()
Expand Down

0 comments on commit 659d15d

Please sign in to comment.