diff options
author | Matthias Radestock <matthias@lshift.net> | 2009-09-30 13:04:56 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@lshift.net> | 2009-09-30 13:04:56 +0100 |
commit | 2ca73466d4c0c7b8d98976a01cddc414f31a3198 (patch) | |
tree | ee7917edaf343a93c5c7728ed0ea00cf493f84f7 /src/tcp_acceptor.erl | |
parent | 4aaea60e8804fd1be95ff915f6b3a4c1e2af158e (diff) | |
download | rabbitmq-server-2ca73466d4c0c7b8d98976a01cddc414f31a3198.tar.gz |
handle errors during connection establishment more gracefully
Diffstat (limited to 'src/tcp_acceptor.erl')
-rw-r--r-- | src/tcp_acceptor.erl | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/tcp_acceptor.erl b/src/tcp_acceptor.erl index aa8b8ad5..bc742561 100644 --- a/src/tcp_acceptor.erl +++ b/src/tcp_acceptor.erl @@ -67,15 +67,20 @@ handle_info({inet_async, LSock, Ref, {ok, Sock}}, {ok, Mod} = inet_db:lookup_socket(LSock), inet_db:register_socket(Sock, Mod), - %% report - {ok, {Address, Port}} = inet:sockname(LSock), - {ok, {PeerAddress, PeerPort}} = inet:peername(Sock), - error_logger:info_msg("accepted TCP connection on ~s:~p from ~s:~p~n", - [inet_parse:ntoa(Address), Port, - inet_parse:ntoa(PeerAddress), PeerPort]), - - %% handle - apply(M, F, A ++ [Sock]), + try + %% report + {Address, Port} = inet_op(fun () -> inet:sockname(LSock) end), + {PeerAddress, PeerPort} = inet_op(fun () -> inet:peername(Sock) end), + error_logger:info_msg("accepted TCP connection on ~s:~p from ~s:~p~n", + [inet_parse:ntoa(Address), Port, + inet_parse:ntoa(PeerAddress), PeerPort]), + %% handle + apply(M, F, A ++ [Sock]) + catch {inet_error, Reason} -> + gen_tcp:close(Sock), + error_logger:error_msg("unable to accept TCP connection: ~p~n", + [Reason]) + end, %% accept more case prim_inet:async_accept(LSock, -1) of @@ -95,3 +100,7 @@ terminate(_Reason, _State) -> code_change(_OldVsn, State, _Extra) -> {ok, State}. + +%%-------------------------------------------------------------------- + +inet_op(F) -> rabbit_misc:throw_on_error(inet_error, F). |