@@ -67,15 +67,20 @@ handle_info({inet_async, LSock, Ref, {ok, Sock}},
6767 {ok , Mod } = inet_db :lookup_socket (LSock ),
6868 inet_db :register_socket (Sock , Mod ),
6969
70- % % report
71- {ok , {Address , Port }} = inet :sockname (LSock ),
72- {ok , {PeerAddress , PeerPort }} = inet :peername (Sock ),
73- error_logger :info_msg (" accepted TCP connection on ~s :~p from ~s :~p~n " ,
74- [inet_parse :ntoa (Address ), Port ,
75- inet_parse :ntoa (PeerAddress ), PeerPort ]),
76-
77- % % handle
78- apply (M , F , A ++ [Sock ]),
70+ try
71+ % % report
72+ {Address , Port } = inet_op (fun () -> inet :sockname (LSock ) end ),
73+ {PeerAddress , PeerPort } = inet_op (fun () -> inet :peername (Sock ) end ),
74+ error_logger :info_msg (" accepted TCP connection on ~s :~p from ~s :~p~n " ,
75+ [inet_parse :ntoa (Address ), Port ,
76+ inet_parse :ntoa (PeerAddress ), PeerPort ]),
77+ % % handle
78+ apply (M , F , A ++ [Sock ])
79+ catch {inet_error , Reason } ->
80+ gen_tcp :close (Sock ),
81+ error_logger :error_msg (" unable to accept TCP connection: ~p~n " ,
82+ [Reason ])
83+ end ,
7984
8085 % % accept more
8186 case prim_inet :async_accept (LSock , - 1 ) of
@@ -95,3 +100,7 @@ terminate(_Reason, _State) ->
95100
96101code_change (_OldVsn , State , _Extra ) ->
97102 {ok , State }.
103+
104+ % %--------------------------------------------------------------------
105+
106+ inet_op (F ) -> rabbit_misc :throw_on_error (inet_error , F ).
0 commit comments