Skip to content

Commit 891ddcb

Browse files
michaelklishinmergify[bot]
authored andcommitted
rabbit_networking:ranch_ref/1: use the user-provided IP address/interface
otherwise the ref is miscalculated and certain code paths that depend on the ref correctness will fail. For example, `rabbit_maintenance:{suspend,resume}_all_client_listeners/0`. Closes #8415. Pair: @lhoguin (cherry picked from commit 07a6926)
1 parent 6f59c3b commit 891ddcb

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

deps/rabbit/src/rabbit_networking.erl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,24 @@ ranch_ref(#listener{port = Port}) ->
234234
{acceptor, IPAddress, Port};
235235
ranch_ref(Listener) when is_list(Listener) ->
236236
Port = rabbit_misc:pget(port, Listener),
237-
[{IPAddress, Port, _Family} | _] = tcp_listener_addresses(Port),
237+
IPAddress = case rabbit_misc:pget(ip, Listener) of
238+
undefined ->
239+
[{Value, _Port, _Family} | _] = tcp_listener_addresses(Port),
240+
Value;
241+
Value when is_list(Value) ->
242+
%% since we only use this function to parse the address, only one result should
243+
%% be returned
244+
[{Parsed, _Family} | _] = gethostaddr(Value, auto),
245+
Parsed;
246+
Value when is_binary(Value) ->
247+
Str = rabbit_data_coercion:to_list(Value),
248+
%% since we only use this function to parse the address, only one result should
249+
%% be returned
250+
[{Parsed, _Family} | _] = gethostaddr(Str, auto),
251+
Parsed;
252+
Value when is_tuple(Value) ->
253+
Value
254+
end,
238255
{acceptor, IPAddress, Port};
239256
ranch_ref(undefined) ->
240257
undefined.
@@ -637,6 +654,7 @@ getaddr(Host, Family) ->
637654
{error, _} -> gethostaddr(Host, Family)
638655
end.
639656

657+
-spec gethostaddr(string(), inet:address_family() | 'auto') -> [{inet:ip_address(), inet:address_family()}].
640658
gethostaddr(Host, auto) ->
641659
Lookups = [{Family, inet:getaddr(Host, Family)} || Family <- [inet, inet6]],
642660
case [{IP, Family} || {Family, {ok, IP}} <- Lookups] of

0 commit comments

Comments
 (0)