@@ -367,13 +367,29 @@ force_connection_event_refresh(Ref) ->
367
367
[rabbit_reader :force_event_refresh (C , Ref ) || C <- connections ()],
368
368
ok .
369
369
370
- handshake (Ref , ProxyProtocol ) ->
371
- case ProxyProtocol of
370
+ failed_to_recv_proxy_header (Ref , Error ) ->
371
+ Msg = case Error of
372
+ closed -> " error when receiving proxy header: TCP socket was ~p prematurely" ;
373
+ _Other -> " error when receiving proxy header: ~p "
374
+ end ,
375
+ rabbit_log :error (Msg , [Error ]),
376
+ % The following call will clean up resources then exit
377
+ _ = ranch :handshake (Ref ),
378
+ exit ({shutdown , failed_to_recv_proxy_header }).
379
+
380
+ handshake (Ref , ProxyProtocolEnabled ) ->
381
+ case ProxyProtocolEnabled of
372
382
true ->
373
- {ok , ProxyInfo } = ranch :recv_proxy_header (Ref , 1000 ),
374
- {ok , Sock } = ranch :handshake (Ref ),
375
- setup_socket (Sock ),
376
- {ok , {rabbit_proxy_socket , Sock , ProxyInfo }};
383
+ case ranch :recv_proxy_header (Ref , 3000 ) of
384
+ {error , Error } ->
385
+ failed_to_recv_proxy_header (Ref , Error );
386
+ {error , protocol_error , Error } ->
387
+ failed_to_recv_proxy_header (Ref , Error );
388
+ {ok , ProxyInfo } ->
389
+ {ok , Sock } = ranch :handshake (Ref ),
390
+ setup_socket (Sock ),
391
+ {ok , {rabbit_proxy_socket , Sock , ProxyInfo }}
392
+ end ;
377
393
false ->
378
394
{ok , Sock } = ranch :handshake (Ref ),
379
395
setup_socket (Sock ),
0 commit comments