summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2012-01-25 14:26:40 +0000
committerMatthias Radestock <matthias@rabbitmq.com>2012-01-25 14:26:40 +0000
commitceb1c9a7aac2e7401f9e803569dceb9f37c9add0 (patch)
treeb2e013307e0faec2e716765a9d9f64ad231d1ad1
parent0a87460cc005912389c107cd1f89350097791557 (diff)
downloadrabbitmq-server-ceb1c9a7aac2e7401f9e803569dceb9f37c9add0.tar.gz
do not log accepted connections in tcp_acceptor
Logging in such generic code should be very sparse. Let's leave that to application code (rabbit_reader et al in case of rabbit) instead.
-rw-r--r--src/tcp_acceptor.erl42
1 files changed, 16 insertions, 26 deletions
diff --git a/src/tcp_acceptor.erl b/src/tcp_acceptor.erl
index 8678c2c9..4515d8e2 100644
--- a/src/tcp_acceptor.erl
+++ b/src/tcp_acceptor.erl
@@ -54,28 +54,17 @@ handle_info({inet_async, LSock, Ref, {ok, Sock}},
{ok, Mod} = inet_db:lookup_socket(LSock),
inet_db:register_socket(Sock, Mod),
- 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",
- [rabbit_misc:ntoab(Address), Port,
- rabbit_misc:ntoab(PeerAddress), PeerPort]),
- %% In the event that somebody floods us with connections we can spew
- %% the above message at error_logger faster than it can keep up.
- %% So error_logger's mailbox grows unbounded until we eat all the
- %% memory available and crash. So here's a meaningless synchronous call
- %% to the underlying gen_event mechanism - when it returns the mailbox
- %% is drained.
- gen_event:which_handlers(error_logger),
- %% handle
- file_handle_cache:transfer(apply(M, F, A ++ [Sock])),
- ok = file_handle_cache:obtain()
- catch {inet_error, Reason} ->
- gen_tcp:close(Sock),
- error_logger:error_msg("unable to accept TCP connection: ~p~n",
- [Reason])
- end,
+ %% In the event that somebody floods us with connections we can
+ %% spew log events at error_logger faster than it can keep up. So
+ %% error_logger's mailbox grows unbounded until we eat all the
+ %% memory available and crash. So here's a meaningless synchronous
+ %% call to the underlying gen_event mechanism - when it returns
+ %% the mailbox is drained.
+ gen_event:which_handlers(error_logger),
+
+ %% handle
+ file_handle_cache:transfer(apply(M, F, A ++ [Sock])),
+ ok = file_handle_cache:obtain(),
%% accept more
accept(State);
@@ -88,9 +77,12 @@ handle_info({inet_async, LSock, Ref, {error, closed}},
handle_info({inet_async, LSock, Ref, {error, Reason}},
State=#state{sock=LSock, ref=Ref}) ->
- {Address, Port} = inet_op(fun () -> inet:sockname(LSock) end),
+ {AddressS, Port} = case inet:sockname(LSock) of
+ {ok, {A, P}} -> {rabbit_misc:ntoab(A), P};
+ {error, _} -> {"unknown", unknown}
+ end,
error_logger:error_msg("failed to accept TCP connection on ~s:~p: ~p~n",
- [rabbit_misc:ntoab(Address), Port, Reason]),
+ [AddressS, Port, Reason]),
accept(State);
handle_info(_Info, State) ->
@@ -104,8 +96,6 @@ code_change(_OldVsn, State, _Extra) ->
%%--------------------------------------------------------------------
-inet_op(F) -> rabbit_misc:throw_on_error(inet_error, F).
-
accept(State = #state{sock=LSock}) ->
case prim_inet:async_accept(LSock, -1) of
{ok, Ref} -> {noreply, State#state{ref=Ref}};