瀏覽代碼

Introduce an option to not trap process exits in worker processes

When worker processes are part of an external connection pool it may make sense
to rely on automatic cleanup based on links. Since by default worker processes
trap exits, linked proceses would fail to terminate the ibrowse worker and
instead it would generate an '{'EXIT', Pid, Reason}' which is handled in
handle_info/2 with a warning to stdout.

Add a new option to allow users to control worker process link behavior via an
ibrowse config parameter. The default stays the same (=true).
pull/171/head
Nick Vatamaniuc 4 年之前
父節點
當前提交
12b14f9c79
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: FC04DFBC9657A78E
共有 1 個檔案被更改,包括 9 行新增3 行删除
  1. +9
    -3
      src/ibrowse_http_client.erl

+ 9
- 3
src/ibrowse_http_client.erl 查看文件

@ -133,7 +133,7 @@ send_req(Conn_Pid, Url, Headers, Method, Body, Options, Timeout) ->
%% {stop, Reason}
%%--------------------------------------------------------------------
init({Lb_Tid, #url{host = Host, port = Port}, {SSLOptions, Is_ssl}}) ->
process_flag(trap_exit, true),
maybe_trap_exits(),
State = #state{host = Host,
port = Port,
ssl_options = SSLOptions,
@ -143,7 +143,7 @@ init({Lb_Tid, #url{host = Host, port = Port}, {SSLOptions, Is_ssl}}) ->
put(my_trace_flag, ibrowse_lib:get_trace_status(Host, Port)),
{ok, set_inac_timer(State)};
init(Url) when is_list(Url) ->
process_flag(trap_exit, true),
maybe_trap_exits(),
case catch ibrowse_lib:parse_url(Url) of
#url{protocol = Protocol} = Url_rec ->
init({undefined, Url_rec, {[], Protocol == https}});
@ -151,7 +151,7 @@ init(Url) when is_list(Url) ->
{error, invalid_url}
end;
init({Host, Port}) ->
process_flag(trap_exit, true),
maybe_trap_exits(),
State = #state{host = Host,
port = Port},
put(ibrowse_trace_token, [Host, $:, integer_to_list(Port)]),
@ -2187,3 +2187,9 @@ get_header_value(Name, Headers, Default_val) ->
delayed_stop_timer() ->
erlang:send_after(500, self(), delayed_stop).
maybe_trap_exits() ->
case ibrowse:get_config_value(worker_trap_exits, true) of
true -> process_flag(trap_exit, true);
false -> ok
end.

Loading…
取消
儲存