mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 09:49:18 +02:00
ejabberd_listener: Use init_fail for errors as recommended by init_ack
That is recommended since OTP 26, see https://www.erlang.org/doc/apps/stdlib/proc_lib.html#init_ack/2 Warning Do not use this function to return an error indicating that the process start failed. When doing so the start function can return before the failing process has exited, which may block VM resources required for a new start attempt to succeed. Use init_fail/2,3 for that purpose.
This commit is contained in:
parent
8b61cf0742
commit
38b203feb1
1 changed files with 25 additions and 21 deletions
|
@ -139,16 +139,13 @@ init({Port, _, udp} = EndPoint, Module, Opts, SockOpts) ->
|
||||||
{error, _} ->
|
{error, _} ->
|
||||||
ok
|
ok
|
||||||
end;
|
end;
|
||||||
{error, Reason} = Err ->
|
{error, Reason} ->
|
||||||
report_socket_error(Reason, EndPoint, Module),
|
return_socket_error(Reason, EndPoint, Module)
|
||||||
proc_lib:init_ack(Err)
|
|
||||||
end;
|
end;
|
||||||
{{error, Reason} = Err, _} ->
|
{{error, Reason}, _} ->
|
||||||
report_socket_error(Reason, EndPoint, Module),
|
return_socket_error(Reason, EndPoint, Module);
|
||||||
proc_lib:init_ack(Err);
|
{_, {error, Reason} } ->
|
||||||
{_, {error, Reason} = Err} ->
|
return_socket_error(Reason, EndPoint, Module)
|
||||||
report_socket_error(Reason, EndPoint, Module),
|
|
||||||
proc_lib:init_ack(Err)
|
|
||||||
end;
|
end;
|
||||||
init({Port, _, tcp} = EndPoint, Module, Opts, SockOpts) ->
|
init({Port, _, tcp} = EndPoint, Module, Opts, SockOpts) ->
|
||||||
case {listen_tcp(Port, SockOpts),
|
case {listen_tcp(Port, SockOpts),
|
||||||
|
@ -177,16 +174,13 @@ init({Port, _, tcp} = EndPoint, Module, Opts, SockOpts) ->
|
||||||
{error, _} ->
|
{error, _} ->
|
||||||
ok
|
ok
|
||||||
end;
|
end;
|
||||||
{error, Reason} = Err ->
|
{error, Reason} ->
|
||||||
report_socket_error(Reason, EndPoint, Module),
|
return_socket_error(Reason, EndPoint, Module)
|
||||||
proc_lib:init_ack(Err)
|
|
||||||
end;
|
end;
|
||||||
{{error, Reason}, _} = Err ->
|
{{error, Reason}, _} ->
|
||||||
report_socket_error(Reason, EndPoint, Module),
|
return_socket_error(Reason, EndPoint, Module);
|
||||||
proc_lib:init_ack(Err);
|
{_, {error, Reason}} ->
|
||||||
{_, {error, Reason}} = Err ->
|
return_socket_error(Reason, EndPoint, Module)
|
||||||
report_socket_error(Reason, EndPoint, Module),
|
|
||||||
proc_lib:init_ack(Err)
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec listen_tcp(inet:port_number(), [gen_tcp:option()]) ->
|
-spec listen_tcp(inet:port_number(), [gen_tcp:option()]) ->
|
||||||
|
@ -608,10 +602,20 @@ config_reloaded() ->
|
||||||
end
|
end
|
||||||
end, New).
|
end, New).
|
||||||
|
|
||||||
-spec report_socket_error(inet:posix(), endpoint(), module()) -> ok.
|
|
||||||
report_socket_error(Reason, EndPoint, Module) ->
|
-spec return_socket_error(inet:posix(), endpoint(), module()) -> ok.
|
||||||
|
return_socket_error(Reason, EndPoint, Module) ->
|
||||||
?ERROR_MSG("Failed to open socket at ~ts for ~ts: ~ts",
|
?ERROR_MSG("Failed to open socket at ~ts for ~ts: ~ts",
|
||||||
[format_endpoint(EndPoint), Module, format_error(Reason)]).
|
[format_endpoint(EndPoint), Module, format_error(Reason)]),
|
||||||
|
return_init_error(Reason).
|
||||||
|
|
||||||
|
-ifdef(OTP_BELOW_26).
|
||||||
|
return_init_error(Reason) ->
|
||||||
|
proc_lib:init_ack({error, Reason}).
|
||||||
|
-else.
|
||||||
|
return_init_error(Reason) ->
|
||||||
|
proc_lib:init_fail({error, Reason}, {exit, normal}).
|
||||||
|
-endif.
|
||||||
|
|
||||||
-spec format_error(inet:posix() | atom()) -> string().
|
-spec format_error(inet:posix() | atom()) -> string().
|
||||||
format_error(Reason) ->
|
format_error(Reason) ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue