Skip to content

Commit

Permalink
Work around race in cover:is_compiled/1
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbbell committed Nov 27, 2024
1 parent 3e9907d commit 89a0081
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/horus.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,7 @@ get_object_code(Module) ->
%% @private

do_get_object_code(Module) ->
case cover:is_compiled(Module) of
case is_cover_compiled(Module) of
false ->
get_object_code_from_code_server(Module);
{file, Filename} ->
Expand All @@ -2008,6 +2008,18 @@ do_get_object_code(Module) ->
erpc:call(CoverMainNode, ?MODULE, do_get_object_code, [Module])
end.

is_cover_compiled(Module) ->
try
cover:is_compiled(Module)
catch
error:{badmatch, {error, {already_started, _}}} ->
%% The code in `cover' that checks if the cover server is started
%% seem racy. We get an exception if it thinks it has to start it
%% but it is already started. In this case, we retry the call.
timer:sleep(100),
cover:is_compiled(Module)
end.

get_object_code_from_code_server(Module) ->
case code:get_object_code(Module) of
{Module, Beam, Filename} ->
Expand Down

0 comments on commit 89a0081

Please sign in to comment.