From 40eeacd3975e76ffb21f7c836760e69e1c5fb775 Mon Sep 17 00:00:00 2001 From: Paul Dann Date: Mon, 2 May 2022 17:32:04 +0100 Subject: [PATCH] Handle "unavailable" schema module status more correctly The Elixir documentation specifies for Code.ensure_compiled/1 that {:error, :unavailable} is not necessarily an error condition, as the deadlock could still be broken by the compiler. So we give the compiler a little time to break the deadlock and retry a number of times before we give up. --- lib/absinthe/plug.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/absinthe/plug.ex b/lib/absinthe/plug.ex index e1e6eb7..a14ebdf 100644 --- a/lib/absinthe/plug.ex +++ b/lib/absinthe/plug.ex @@ -260,12 +260,16 @@ defmodule Absinthe.Plug do schema end - defp valid_schema_module?(module) do + defp valid_schema_module?(module, retries \\ 0) do with true <- is_atom(module), {:module, _} <- Code.ensure_compiled(module), true <- Absinthe.Schema in Keyword.get(module.__info__(:attributes), :behaviour, []) do true else + {:error, :unavailable} when retries < 100 -> + Process.sleep(100) + valid_schema_module?(module, retries + 1) + _ -> false end end