Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

horus: Work around race in cover:is_compiled/1 #28

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

dumbbell
Copy link
Member

Why

The cover:call/1 internal checks if the cover server is running and starts it if it's not:

Ref = erlang:monitor(process,?SERVER),
receive {'DOWN', Ref, _Type, _Object, noproc} ->
    erlang:demonitor(Ref),
    {ok,_} = start(),
    ...

However, there is no lock between the check and
the start. Therefore, any concurrent uses of this code may cause a badmatch crash on {ok,_} = start() because it might have been started in parallel and the function returns the already_started error.

How

To work around the problem, we catch the badmatch and retry once after a sleep of 100 ms. We don't try to catch any exception from that second attempt.

[Why]
The `cover:call/1` internal checks if the cover server is running and
starts it if it's not:

    Ref = erlang:monitor(process,?SERVER),
    receive {'DOWN', Ref, _Type, _Object, noproc} ->
            erlang:demonitor(Ref),
            {ok,_} = start(),
            ...

However, there is no lock between the check and
the start. Therefore, any concurrent uses of this code may cause a
`badmatch` crash on `{ok,_} = start()` because it might have been
started in parallel and the function returns the `already_started`
error.

[How]
To work around the problem, we catch the `badmatch` and retry once after
a sleep of 100 ms. We don't try to catch any exception from that second
attempt.
@dumbbell dumbbell added the bug Something isn't working label Nov 27, 2024
@dumbbell dumbbell self-assigned this Nov 27, 2024
@dumbbell dumbbell added this to the v0.3.1 milestone Nov 27, 2024
Copy link

codecov bot commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 84.26%. Comparing base (3e9907d) to head (99a2075).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/horus.erl 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
- Coverage   84.41%   84.26%   -0.15%     
==========================================
  Files           3        3              
  Lines         943      947       +4     
==========================================
+ Hits          796      798       +2     
- Misses        147      149       +2     
Flag Coverage Δ
erlang-25 82.89% <60.00%> (-0.15%) ⬇️
erlang-26 78.29% <60.00%> (-0.13%) ⬇️
erlang-27 69.14% <60.00%> (-0.09%) ⬇️
os-ubuntu-latest 84.26% <60.00%> (+5.84%) ⬆️
os-windows-latest 84.26% <60.00%> (-0.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dumbbell dumbbell marked this pull request as ready for review November 27, 2024 17:52
@dumbbell dumbbell merged commit ce0d28b into main Nov 27, 2024
24 checks passed
@dumbbell dumbbell deleted the work-around-race-in-cover-is_compiled branch November 27, 2024 17:52
@dumbbell
Copy link
Member Author

A patch to fix the root problem was submitted upstream in erlang/otp#9124.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant