This is an automated email from the ASF dual-hosted git repository. davisp pushed a commit to branch optimize-ddoc-cache in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit e87bbe72351a6050ccc49a00174f2efa2b2271db Author: Paul J. Davis <[email protected]> AuthorDate: Thu Jul 20 14:02:57 2017 -0500 FIXUP: Process processes in the process of dying Turns out we could go to evict an entry just after it had decided to leave the cache (i.e., its ddoc was just deleted). When that happens ddoc_cache_lru would die trying to shut the process down becuase the process died normal earlier than expected. --- src/ddoc_cache/src/ddoc_cache_entry.erl | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ddoc_cache/src/ddoc_cache_entry.erl b/src/ddoc_cache/src/ddoc_cache_entry.erl index 63a2efa..77539eb 100644 --- a/src/ddoc_cache/src/ddoc_cache_entry.erl +++ b/src/ddoc_cache/src/ddoc_cache_entry.erl @@ -77,7 +77,17 @@ start_link(Key, Default) -> shutdown(Pid) -> - ok = gen_server:call(Pid, shutdown). + Ref = erlang:monitor(process, Pid), + ok = gen_server:cast(Pid, shutdown), + receive + {'DOWN', Ref, process, Pid, normal} -> + ok; + {'DOWN', Ref, process, Pid, Reason} -> + erlang:exit(Reason) + after ?SHUTDOWN_TIMEOUT -> + erlang:demonitor(Ref, [flush]), + erlang:exit({timeout, {entry_shutdown, Pid}}) + end. open(Pid, Key) -> @@ -170,10 +180,6 @@ handle_call(open, From, #st{opener = Pid} = St) when is_pid(Pid) -> handle_call(open, _From, St) -> {reply, St#st.val, St}; -handle_call(shutdown, _From, St) -> - remove_from_cache(St), - {stop, normal, ok, St}; - handle_call(Msg, _From, St) -> {stop, {bad_call, Msg}, {bad_call, Msg}, St}. @@ -227,6 +233,10 @@ handle_cast(refresh, #st{opener = Pid} = St) when is_pid(Pid) -> }, {noreply, NewSt}; +handle_cast(shutdown, St) -> + remove_from_cache(St), + {stop, normal, St}; + handle_cast(Msg, St) -> {stop, {bad_cast, Msg}, St}. -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
