This is an automated email from the ASF dual-hosted git repository. vatamane pushed a commit to branch fix-index-server-premature-return in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 73c8adadfb39e9ce67ac5c09707a86f6238e3fba Author: Nick Vatamaniuc <[email protected]> AuthorDate: Tue Oct 17 01:25:57 2023 -0400 Fix index server crash when async opener returns too early Previously, the index process and the still linked async opener processes could have crashed, after we already replied the the waiting clients. That would genarate two `EXIT` messages: one for the indexer pid, and one for the opener. By the time the opener `EXIT` was handled, the `st.openers` entry was already missing (since handle_call of async_open could delete it), and so the index server itself would crash. --- src/couch_index/src/couch_index_server.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/couch_index/src/couch_index_server.erl b/src/couch_index/src/couch_index_server.erl index 35df43d2a..5055382d5 100644 --- a/src/couch_index/src/couch_index_server.erl +++ b/src/couch_index/src/couch_index_server.erl @@ -169,16 +169,16 @@ handle_call({get_index, {_Mod, _IdxState, DbName, Sig} = Args}, From, State) -> end; handle_call({async_open, {DbName, DDocId, Sig}, {ok, Pid}}, {OpenerPid, _}, State) -> [{_, Waiters}] = ets:lookup(State#st.by_sig, {DbName, Sig}), - [gen_server:reply(From, {ok, Pid}) || From <- Waiters], link(Pid), ets:delete(State#st.openers, OpenerPid), add_to_ets(DbName, Sig, DDocId, Pid, State), + [gen_server:reply(From, {ok, Pid}) || From <- Waiters], {reply, ok, State}; handle_call({async_error, {DbName, _DDocId, Sig}, Error}, {OpenerPid, _}, State) -> [{_, Waiters}] = ets:lookup(State#st.by_sig, {DbName, Sig}), - [gen_server:reply(From, Error) || From <- Waiters], ets:delete(State#st.openers, OpenerPid), ets:delete(State#st.by_sig, {DbName, Sig}), + [gen_server:reply(From, Error) || From <- Waiters], {reply, ok, State}; handle_call({reset_indexes, DbName}, _From, State) -> reset_indexes(DbName, State),
