@@ -389,13 +389,29 @@ force_connection_event_refresh(Ref) ->
389
389
[rabbit_reader :force_event_refresh (C , Ref ) || C <- connections ()],
390
390
ok .
391
391
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
394
404
true ->
395
- {ok , ProxyInfo } = ranch :recv_proxy_header (Ref , 1000 ),
396
- {ok , Sock } = ranch :handshake (Ref ),
397
- setup_socket (Sock ),
398
- {ok , {rabbit_proxy_socket , Sock , ProxyInfo }};
405
+ case ranch :recv_proxy_header (Ref , 3000 ) of
406
+ {error , Error } ->
407
+ failed_to_recv_proxy_header (Ref , Error );
408
+ {error , protocol_error , Error } ->
409
+ failed_to_recv_proxy_header (Ref , Error );
410
+ {ok , ProxyInfo } ->
411
+ {ok , Sock } = ranch :handshake (Ref ),
412
+ setup_socket (Sock ),
413
+ {ok , {rabbit_proxy_socket , Sock , ProxyInfo }}
414
+ end ;
399
415
false ->
400
416
{ok , Sock } = ranch :handshake (Ref ),
401
417
setup_socket (Sock ),
0 commit comments