Permalink
Browse files

Update src/ibrowse_lb.erl

ets:update_counter crashes when select process has shutdown.
  • Loading branch information...
1 parent d8c2e5a commit bb9fe3078e74faa6d8a6e129b28ab20a112c922f @marutha marutha committed Dec 7, 2012
Showing with 9 additions and 3 deletions.
  1. +9 −3 src/ibrowse_lb.erl
View
@@ -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.

0 comments on commit bb9fe30

Please sign in to comment.