From bb9fe3078e74faa6d8a6e129b28ab20a112c922f Mon Sep 17 00:00:00 2001 From: maruthavanan Date: Fri, 7 Dec 2012 16:10:02 +0530 Subject: [PATCH 1/3] Update src/ibrowse_lb.erl ets:update_counter crashes when select process has shutdown. --- src/ibrowse_lb.erl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ibrowse_lb.erl b/src/ibrowse_lb.erl index d98cf32..69f4661 100644 --- a/src/ibrowse_lb.erl +++ b/src/ibrowse_lb.erl @@ -230,7 +230,9 @@ code_change(_OldVsn, State, _Extra) -> %%% Internal functions %%-------------------------------------------------------------------- find_best_connection(Tid, Max_pipe) -> + ets:safe_fixtable(Tid, true), Res = find_best_connection(ets:first(Tid), Tid, Max_pipe), + ets:safe_fixtable(Tid, false), Res. find_best_connection('$end_of_table', _, _) -> @@ -239,9 +241,13 @@ find_best_connection(Pid, Tid, Max_pipe) -> case ets:lookup(Tid, Pid) of [{Pid, Cur_sz, Speculative_sz}] when Cur_sz < Max_pipe, Speculative_sz < Max_pipe -> - ets:update_counter(Tid, Pid, {3, 1, 9999999, 9999999}), - {ok, Pid}; - _ -> + case catch ets:update_counter(Tid, Pid, {3, 1, 9999999, 9999999}) of + {'EXIT', _} -> + %% The selected process has shutdown + find_best_connection(ets:next(Tid, Pid), Tid, Max_pipe); + _ -> + {ok, Pid} + end; _ -> find_best_connection(ets:next(Tid, Pid), Tid, Max_pipe) end. From 7c55ac9fc6c05d67a24459a1b5ad49e2dadefb90 Mon Sep 17 00:00:00 2001 From: maruthavanan Date: Fri, 7 Dec 2012 16:14:40 +0530 Subject: [PATCH 2/3] Update src/ibrowse_lb.erl ets update counter throws exception when the corresponding process has already shutdown. Added line fee to L248 --- src/ibrowse_lb.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ibrowse_lb.erl b/src/ibrowse_lb.erl index 69f4661..316e8e2 100644 --- a/src/ibrowse_lb.erl +++ b/src/ibrowse_lb.erl @@ -247,7 +247,8 @@ find_best_connection(Pid, Tid, Max_pipe) -> find_best_connection(ets:next(Tid, Pid), Tid, Max_pipe); _ -> {ok, Pid} - end; _ -> + end; +_ -> find_best_connection(ets:next(Tid, Pid), Tid, Max_pipe) end. From f7a98b1ef9d1f75819d7d9f10548f5c76b03fac8 Mon Sep 17 00:00:00 2001 From: maruthavanan Date: Fri, 7 Dec 2012 16:16:38 +0530 Subject: [PATCH 3/3] Update src/ibrowse_lb.erl --- src/ibrowse_lb.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ibrowse_lb.erl b/src/ibrowse_lb.erl index 316e8e2..993e8d4 100644 --- a/src/ibrowse_lb.erl +++ b/src/ibrowse_lb.erl @@ -248,7 +248,7 @@ find_best_connection(Pid, Tid, Max_pipe) -> _ -> {ok, Pid} end; -_ -> + _ -> find_best_connection(ets:next(Tid, Pid), Tid, Max_pipe) end.