Skip to content

Commit

Permalink
Work around a race condition when deleting slide counters
Browse files Browse the repository at this point in the history
If SampleMod:trim/2 gets called by a folsom_sample_slide_server after the ETS table the server is trimming has gone away, it will go into a restart loop and eventually bring down the folsom_sample_slide_sup supervisor.
This fixes that by catching badarg and stopping the erronous process normally.
  • Loading branch information
Sölvi Páll Ásgeirsson committed Oct 27, 2015
1 parent 8914823 commit 21a3dd9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/folsom_sample_slide_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ handle_cast(_Msg, State) ->
{noreply, State}.

handle_info(timeout, State=#state{sample_mod = SampleMod, reservoir = Reservoir, window = Window}) ->
SampleMod:trim(Reservoir, Window),
{noreply, State, timeout(Window)};
try
SampleMod:trim(Reservoir, Window),
{noreply, State, timeout(Window)}
catch error:badarg ->
%% The ets table must have gone away; stop normally instead of bringing
%% the supervisor down with us.
{stop, normal, State}
end;
handle_info(_Info, State) ->
{noreply, State}.

Expand Down

0 comments on commit 21a3dd9

Please sign in to comment.