Skip to content

Commit

Permalink
cover: Fix a race condition in how the server is started as part of a…
Browse files Browse the repository at this point in the history
… call

[Why]
Before sending a message to the cover server, the `call` function checks
if the server is running, starting it if it does not.

However, there is no locking/atomicity between the check and the start.
If there is a concurrent call, the server might be started in parallel
by another process and the `start()` call would return
`{already_started, _}`. This causes the function to fail with the
`badmatch` exception.

[How]
The code now accepts that the server is running after seeing the server
as stopped and retrying the call.
  • Loading branch information
dumbbell committed Nov 27, 2024
1 parent c9848b6 commit 9587c7a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/tools/src/cover.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,10 @@ call(Request) ->
Ref = erlang:monitor(process,?SERVER),
receive {'DOWN', Ref, _Type, _Object, noproc} ->
erlang:demonitor(Ref),
{ok,_} = start(),
ok = case start() of
{ok,_} -> ok;
{'already_started',_} -> ok
end,
call(Request)
after 0 ->
?SERVER ! {self(),Request},
Expand Down

0 comments on commit 9587c7a

Please sign in to comment.