From afccba0bfae36df0748145db34956fab72159234 Mon Sep 17 00:00:00 2001 From: Chandrashekhar Mullaparthi Date: Wed, 13 Aug 2014 11:10:15 +0100 Subject: [PATCH] Cleanup correctly on shutdown --- src/ibrowse_lb.erl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ibrowse_lb.erl b/src/ibrowse_lb.erl index a802f87..88b169b 100644 --- a/src/ibrowse_lb.erl +++ b/src/ibrowse_lb.erl @@ -112,10 +112,7 @@ handle_call(stop, _From, #state{ets_tid = undefined} = State) -> {stop, normal, State}; handle_call(stop, _From, #state{ets_tid = Tid} = State) -> - ets:foldl(fun({Pid, _, _}, Acc) -> - ibrowse_http_client:stop(Pid), - Acc - end, [], Tid), + stop_all_conn_procs(Tid), gen_server:reply(_From, ok), {stop, normal, State}; @@ -196,10 +193,17 @@ handle_info(_Info, State) -> %% Description: Shutdown the server %% Returns: any (ignored by gen_server) %%-------------------------------------------------------------------- -terminate(_Reason, #state{host = Host, port = Port} = _State) -> +terminate(_Reason, #state{host = Host, port = Port, ets_tid = Tid} = _State) -> catch ets:delete(ibrowse_lb, {Host, Port}), + stop_all_conn_procs(Tid), ok. +stop_all_conn_procs(Tid) -> + ets:foldl(fun({{_, _, Pid}, _}, Acc) -> + ibrowse_http_client:stop(Pid), + Acc + end, [], Tid). + %%-------------------------------------------------------------------- %% Func: code_change/3 %% Purpose: Convert process state when code is changed