diff options
| -rw-r--r-- | src/file_handle_cache.erl | 18 | ||||
| -rw-r--r-- | src/rabbit_reader.erl | 1 | ||||
| -rw-r--r-- | src/tcp_acceptor.erl | 4 |
3 files changed, 12 insertions, 11 deletions
diff --git a/src/file_handle_cache.erl b/src/file_handle_cache.erl index ac6de519b7..2519382c19 100644 --- a/src/file_handle_cache.erl +++ b/src/file_handle_cache.erl @@ -124,7 +124,7 @@ -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). --export([release/0, obtain/0]). +-export([release_on_death/1, obtain/0]). -define(SERVER, ?MODULE). -define(RESERVED_FOR_OTHERS, 50). @@ -432,8 +432,8 @@ set_maximum_since_use(MaximumAge) -> false -> ok end. -release() -> - gen_server:cast(?SERVER, release). +release_on_death(Pid) when is_pid(Pid) -> + gen_server:cast(?SERVER, {release_on_death, Pid}). obtain() -> gen_server:call(?SERVER, obtain, infinity). @@ -697,15 +697,17 @@ handle_cast({close, Pid, EldestUnusedSince}, State = {noreply, process_obtains(State #fhc_state { elders = Elders1, count = Count - 1 })}; -handle_cast(release, State = #fhc_state { count = Count }) -> - {noreply, process_obtains(State #fhc_state { count = Count - 1 })}; - handle_cast(check_counts, State) -> - {noreply, maybe_reduce(State)}. + {noreply, maybe_reduce(State)}; -handle_info(_Msg, State) -> +handle_cast({release_on_death, Pid}, State) -> + _MRef = erlang:monitor(process, Pid), {noreply, State}. +handle_info({'DOWN', _MRef, process, _Pid, _Reason}, + State = #fhc_state { count = Count }) -> + {noreply, process_obtains(State #fhc_state { count = Count - 1 })}. + terminate(_Reason, State) -> State. diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index c2818be4dd..adfd412f99 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -234,7 +234,6 @@ start_connection(Parent, Deb, Sock, SockTransform) -> end)("exception on TCP connection ~p from ~s:~p~n~p~n", [self(), PeerAddressS, PeerPort, Ex]) after - file_handle_cache:release(), rabbit_log:info("closing TCP connection ~p from ~s:~p~n", [self(), PeerAddressS, PeerPort]), %% We don't close the socket explicitly. The reader is the diff --git a/src/tcp_acceptor.erl b/src/tcp_acceptor.erl index 9e7962338a..6de6ac3e2e 100644 --- a/src/tcp_acceptor.erl +++ b/src/tcp_acceptor.erl @@ -61,7 +61,7 @@ handle_info({inet_async, LSock, Ref, {ok, Sock}}, State = #state{callback={M,F,A}, sock=LSock, ref=Ref}) -> %% patch up the socket so it looks like one we got from - %% gen_tcp:accept/1 + %% gen_tcp:accept/1 {ok, Mod} = inet_db:lookup_socket(LSock), inet_db:register_socket(Sock, Mod), @@ -73,7 +73,7 @@ handle_info({inet_async, LSock, Ref, {ok, Sock}}, [inet_parse:ntoa(Address), Port, inet_parse:ntoa(PeerAddress), PeerPort]), %% handle - apply(M, F, A ++ [Sock]) + file_handle_cache:release_on_death(apply(M, F, A ++ [Sock])) catch {inet_error, Reason} -> gen_tcp:close(Sock), error_logger:error_msg("unable to accept TCP connection: ~p~n", |
