Skip to content

Commit d26a2af

Browse files
Handle error triples, improve logging
1 parent c1e6c63 commit d26a2af

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/rabbit_networking.erl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,24 @@ force_connection_event_refresh(Ref) ->
389389
[rabbit_reader:force_event_refresh(C, Ref) || C <- connections()],
390390
ok.
391391

392-
handshake(Ref, ProxyProtocol) ->
393-
case ProxyProtocol of
392+
failed_to_recv_proxy_header(Ref, Error) ->
393+
Msg = case Error of
394+
closed -> "error when receiving proxy header: TCP socket was ~p prematurely";
395+
_Other -> "error when receiving proxy header: ~p"
396+
end,
397+
rabbit_log:error(Msg, [Error]),
398+
% The following call will clean up resources then exit
399+
_ = ranch:handshake(Ref),
400+
exit({shutdown, failed_to_recv_proxy_header}).
401+
402+
handshake(Ref, ProxyProtocolEnabled) ->
403+
case ProxyProtocolEnabled of
394404
true ->
395-
case ranch:recv_proxy_header(Ref, 1000) of
405+
case ranch:recv_proxy_header(Ref, 3000) of
396406
{error, Error} ->
397-
rabbit_log:error("error when receiving proxy header: ~p", [Error]),
398-
% The following call will clean up resources then exit
399-
should_never_match = ranch:handshake(Ref);
407+
failed_to_recv_proxy_header(Ref, Error);
408+
{error, protocol_error, Error} ->
409+
failed_to_recv_proxy_header(Ref, Error);
400410
{ok, ProxyInfo} ->
401411
{ok, Sock} = ranch:handshake(Ref),
402412
setup_socket(Sock),

0 commit comments

Comments
 (0)