Skip to content

Commit debfb2e

Browse files
author
CI
committed
Sync to GitHub
1 parent 2b8451c commit debfb2e

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

lib/bacnet/beam_types.ex

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ defmodule BACnet.BeamTypes do
703703
)
704704
end
705705

706-
defp get_beam_entity_for_module(module, env) do
706+
defp get_beam_entity_for_module(module, env, retried \\ false) do
707707
# Find the bytecode in our compilation tracer, if not available,
708708
# check if the BEAM file exists and use it instead
709709

@@ -734,11 +734,22 @@ defmodule BACnet.BeamTypes do
734734
if beam_path do
735735
beam_path
736736
else
737-
raise CompileError,
738-
description:
739-
"Missing bytecode for module #{inspect(module)}, unable to lookup types",
740-
file: env.file,
741-
line: env.line
737+
# We retry when all methods fail, because there seems to be
738+
# a race condition, where Code.ensure_compiled!/1 releases
739+
# the lock, but the compilation tracer wasn't called and
740+
# the BEAM file wasn't written yet - by retrying 100ms later,
741+
# it seems that we can successfully resolve the race condition
742+
# and not fail the complete compilation (tested with 200 full runs)
743+
if retried do
744+
raise CompileError,
745+
description:
746+
"Missing bytecode for module #{inspect(module)}, unable to lookup types",
747+
file: env.file,
748+
line: env.line
749+
else
750+
Process.sleep(100)
751+
get_beam_entity_for_module(module, env, true)
752+
end
742753
end
743754
end
744755

0 commit comments

Comments
 (0)