From 21a3dd92a7cf89cf3a9c441c1c137e0f05451ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6lvi=20P=C3=A1ll=20=C3=81sgeirsson?= Date: Tue, 27 Oct 2015 13:58:52 +0000 Subject: [PATCH] Work around a race condition when deleting slide counters 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. --- src/folsom_sample_slide_server.erl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/folsom_sample_slide_server.erl b/src/folsom_sample_slide_server.erl index f02b4a2..a413a34 100644 --- a/src/folsom_sample_slide_server.erl +++ b/src/folsom_sample_slide_server.erl @@ -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}.