diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/couchdb/couch_db.erl | 3 | ||||
-rw-r--r-- | src/couchdb/couch_db_updater.erl | 4 | ||||
-rw-r--r-- | src/couchdb/couch_file.erl | 6 | ||||
-rw-r--r-- | src/couchdb/couch_ref_counter.erl | 3 | ||||
-rw-r--r-- | src/couchdb/couch_server.erl | 3 | ||||
-rw-r--r-- | src/couchdb/couch_util.erl | 10 | ||||
-rw-r--r-- | src/couchdb/couch_view.erl | 4 | ||||
-rw-r--r-- | src/couchdb/couch_view_group.erl | 1 |
8 files changed, 25 insertions, 9 deletions
diff --git a/src/couchdb/couch_db.erl b/src/couchdb/couch_db.erl index 18cb98ee..e7df2f25 100644 --- a/src/couchdb/couch_db.erl +++ b/src/couchdb/couch_db.erl @@ -677,7 +677,8 @@ init({DbName, Filepath, Fd, Options}) -> couch_ref_counter:add(RefCntr), {ok, Db}. -terminate(_Reason, _Db) -> +terminate(Reason, _Db) -> + couch_util:terminate_linked(Reason), ok. handle_call({open_ref_count, OpenerPid}, _, #db{fd_ref_counter=RefCntr}=Db) -> diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl index 969a79d4..ba9be1e4 100644 --- a/src/couchdb/couch_db_updater.erl +++ b/src/couchdb/couch_db_updater.erl @@ -37,7 +37,9 @@ init({MainPid, DbName, Filepath, Fd, Options}) -> Db2 = refresh_validate_doc_funs(Db), {ok, Db2#db{main_pid=MainPid}}. -terminate(_Reason, _Db) -> + +terminate(Reason, _Srv) -> + couch_util:terminate_linked(Reason), ok. handle_call(get_db, _From, Db) -> diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl index 900e369a..b9da5488 100644 --- a/src/couchdb/couch_file.erl +++ b/src/couchdb/couch_file.erl @@ -311,7 +311,7 @@ init({Filepath, Options, ReturnPid, Ref}) -> end. -terminate(_Reason, _Fd) -> +terminate(_Reason, _Fd) -> ok. track_stats() -> @@ -359,5 +359,5 @@ handle_cast(close, Fd) -> code_change(_OldVsn, State, _Extra) -> {ok, State}. -handle_info(foo, _Fd) -> - ok. +handle_info({'EXIT', _, Reason}, Fd) -> + {stop, Reason, Fd}. diff --git a/src/couchdb/couch_ref_counter.erl b/src/couchdb/couch_ref_counter.erl index 95093f72..4c824aa6 100644 --- a/src/couchdb/couch_ref_counter.erl +++ b/src/couchdb/couch_ref_counter.erl @@ -49,7 +49,8 @@ init({Pid, ChildProcs}) -> {ok, #srv{referrers=Referrers}}. -terminate(_Reason, _Srv) -> +terminate(Reason, _Srv) -> + couch_util:terminate_linked(Reason), ok. diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl index 164af094..870d0d76 100644 --- a/src/couchdb/couch_server.erl +++ b/src/couchdb/couch_server.erl @@ -159,7 +159,8 @@ init([]) -> max_dbs_open=MaxDbsOpen, start_time=httpd_util:rfc1123_date()}}. -terminate(_Reason, _Server) -> +terminate(Reason, _Srv) -> + couch_util:terminate_linked(Reason), ok. all_databases() -> diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl index bd377d80..a119cf1c 100644 --- a/src/couchdb/couch_util.erl +++ b/src/couchdb/couch_util.erl @@ -12,7 +12,7 @@ -module(couch_util). --export([start_driver/1]). +-export([start_driver/1,terminate_linked/1]). -export([should_flush/0, should_flush/1, to_existing_atom/1, to_binary/1]). -export([new_uuid/0, rand32/0, implode/2, collate/2, collate/3]). -export([abs_pathname/1,abs_pathname/2, trim/1, ascii_lower/1]). @@ -43,6 +43,14 @@ to_existing_atom(V) when is_atom(V)-> V. +terminate_linked(normal) -> + terminate_linked(shutdown); +terminate_linked(Reason) -> + {links, Links} = process_info(self(), links), + [catch exit(Pid, Reason) || Pid <- Links], + ok. + + new_uuid() -> list_to_binary(to_hex(crypto:rand_bytes(16))). diff --git a/src/couchdb/couch_view.erl b/src/couchdb/couch_view.erl index bac9f635..b74fb47d 100644 --- a/src/couchdb/couch_view.erl +++ b/src/couchdb/couch_view.erl @@ -226,7 +226,9 @@ init([]) -> process_flag(trap_exit, true), {ok, #server{root_dir=RootDir}}. -terminate(_Reason,_State) -> + +terminate(Reason, _Srv) -> + couch_util:terminate_linked(Reason), ok. diff --git a/src/couchdb/couch_view_group.erl b/src/couchdb/couch_view_group.erl index e44d637c..57ee97da 100644 --- a/src/couchdb/couch_view_group.erl +++ b/src/couchdb/couch_view_group.erl @@ -272,6 +272,7 @@ handle_info({'DOWN',_,_,_,_}, State) -> terminate(Reason, State) -> reply_all(State, Reason), + couch_util:terminate_linked(Reason), ok. code_change(_OldVsn, State, _Extra) -> |