From 2a6ad51f1acd4cae30a6e976d00444a1a6931702 Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Thu, 18 Dec 2008 21:43:34 +0000 Subject: fix for crash of couch_server when database non-existant git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@727832 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_file.erl | 8 ++++++-- src/couchdb/couch_server.erl | 2 ++ src/couchdb/couch_view_group.erl | 18 ++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl index 4ed9dc05..06156324 100644 --- a/src/couchdb/couch_file.erl +++ b/src/couchdb/couch_file.erl @@ -40,7 +40,11 @@ open(Filepath, Options) -> ignore -> % get the error receive - {Ref, Error} -> + {Ref, Pid, Error} -> + case process_info(self(), trap_exit) of + {trap_exit, true} -> receive {'EXIT', Pid, _} -> ok end; + {trap_exit, false} -> ok + end, Error end; Error -> @@ -276,7 +280,7 @@ extract_header(Prefix, Bin) -> init_status_error(ReturnPid, Ref, Error) -> - ReturnPid ! {Ref, Error}, + ReturnPid ! {Ref, self(), Error}, ignore. % server functions diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl index fd185bc8..2a2f51e2 100644 --- a/src/couchdb/couch_server.erl +++ b/src/couchdb/couch_server.erl @@ -309,8 +309,10 @@ code_change(_OldVsn, State, _Extra) -> handle_info({'EXIT', Pid, _Reason}, #server{current_dbs_open=DbsOpen}=Server) -> [{Pid, DbName}] = ets:lookup(couch_dbs_by_pid, Pid), + [{DbName, {Pid, LruTime}}] = ets:lookup(couch_dbs_by_name, DbName), true = ets:delete(couch_dbs_by_pid, Pid), true = ets:delete(couch_dbs_by_name, DbName), + true = ets:delete(couch_dbs_by_lru, LruTime), {noreply, Server#server{current_dbs_open=DbsOpen-1}}; handle_info(Info, _Server) -> exit({unknown_message, Info}). diff --git a/src/couchdb/couch_view_group.erl b/src/couchdb/couch_view_group.erl index cbbac92a..84c60428 100644 --- a/src/couchdb/couch_view_group.erl +++ b/src/couchdb/couch_view_group.erl @@ -47,9 +47,19 @@ request_group(Pid, Seq) -> start_link(InitArgs) -> case gen_server:start_link(couch_view_group, {InitArgs, self(), Ref = make_ref()}, []) of - {ok, Pid} -> {ok, Pid}; - ignore -> receive {Ref, Error} -> Error end; - Error -> Error + {ok, Pid} -> + {ok, Pid}; + ignore -> + receive + {Ref, Pid, Error} -> + case process_info(self(), trap_exit) of + {trap_exit, true} -> receive {'EXIT', Pid, _} -> ok end; + {trap_exit, false} -> ok + end, + Error + end; + Error -> + Error end. % init differentiates between temp and design_doc views. It creates a closure @@ -67,7 +77,7 @@ init({InitArgs, ReturnPid, Ref}) -> updater_pid = Pid, group=Group}}; Error -> - ReturnPid ! {Ref, Error}, + ReturnPid ! {Ref, self(), Error}, ignore end. -- cgit v1.2.3