diff options
| author | Matthew Sackman <matthew@lshift.net> | 2010-01-19 12:13:30 +0000 |
|---|---|---|
| committer | Matthew Sackman <matthew@lshift.net> | 2010-01-19 12:13:30 +0000 |
| commit | d84e28ac566667bc259c71149d7e151322e713bd (patch) | |
| tree | 949908c382b7ed1f4de57c71f3832619d32245ad | |
| parent | ff9c5f2bede565788bece4772d979861a0fd68bd (diff) | |
| download | rabbitmq-server-git-d84e28ac566667bc259c71149d7e151322e713bd.tar.gz | |
The motivation for the cast in init is that if the first obtain blocks then without the cast, rabbit won't startup because of the fact that start_link blocks on init thus the boot process won't finish. Switched to monitoring the spawned process which is much much nicer than passing through a fun to be run at the end of the process and is a much more generic solution anyway.
| -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", |
