From commits-return-22767-apmail-couchdb-commits-archive=couchdb.apache.org@couchdb.apache.org Sat Apr 4 23:28:59 2015 Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 18A6017D46 for ; Sat, 4 Apr 2015 23:28:59 +0000 (UTC) Received: (qmail 45166 invoked by uid 500); 4 Apr 2015 23:28:57 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 44898 invoked by uid 500); 4 Apr 2015 23:28:57 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 44107 invoked by uid 99); 4 Apr 2015 23:28:56 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Apr 2015 23:28:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6D380E2F6C; Sat, 4 Apr 2015 23:28:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kxepal@apache.org To: commits@couchdb.apache.org Date: Sat, 04 Apr 2015 23:29:14 -0000 Message-Id: <4c3d8f7ea41f4aaabb33053f5b6742eb@git.apache.org> In-Reply-To: <7e6f3f454a6141008e620dd6cb309fa6@git.apache.org> References: <7e6f3f454a6141008e620dd6cb309fa6@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [19/48] couch commit: updated refs/heads/master to 7776921 Handle couch_auth_terminate gracefully In the case when `authentication_db` is changed we will get DOWN message with the Ref we already forgot. So we keep a list of monitors which we close but didn't receive DOWN message. COUCHDB-2547 Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/70049c44 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/70049c44 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/70049c44 Branch: refs/heads/master Commit: 70049c443098d2f747c6fd5b218092f4eda9a65e Parents: 7d49860 Author: ILYA Khlopotov Authored: Mon Feb 2 11:48:39 2015 -0800 Committer: ILYA Khlopotov Committed: Tue Feb 10 11:03:45 2015 -0800 ---------------------------------------------------------------------- src/couch_auth_cache.erl | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/70049c44/src/couch_auth_cache.erl ---------------------------------------------------------------------- diff --git a/src/couch_auth_cache.erl b/src/couch_auth_cache.erl index 0b15489..a8fdab8 100644 --- a/src/couch_auth_cache.erl +++ b/src/couch_auth_cache.erl @@ -38,6 +38,7 @@ cache_size = 0, db_notifier = nil, db_mon_ref = nil, + closed = [], event_listener = nil }). @@ -231,8 +232,18 @@ handle_info(restart_event_listener, State) -> ?MODULE, handle_db_event, nil, [{dbname, AuthDbName}] ), {noreply, State#state{event_listener=NewListener}}; +handle_info({'DOWN', Ref, _, _, shutdown}, State) -> + {stop, shutdown, State}; handle_info({'DOWN', Ref, _, _, _Reason}, #state{db_mon_ref = Ref} = State) -> - {noreply, reinit_cache(State)}. + {noreply, reinit_cache(State)}; +handle_info({'DOWN', Ref, _, _, Reason}, #state{closed = Closed} = State) -> + case lists:delete(Ref, Closed) of + Closed -> + {stop, Reason, State}; + NewClosed -> + {noreply, reinit_cache(State#state{closed = NewClosed})} + end. + terminate(_Reason, #state{event_listener = Listener}) -> couch_event:stop_listener(Listener), @@ -268,13 +279,14 @@ clear_cache(State) -> State#state{cache_size = 0}. -reinit_cache(State) -> +reinit_cache(#state{db_mon_ref = Ref, closed = Closed} = State) -> NewState = clear_cache(State), AuthDbName = ?l2b(config:get("couch_httpd_auth", "authentication_db")), true = ets:insert(?STATE, {auth_db_name, AuthDbName}), AuthDb = open_auth_db(), true = ets:insert(?STATE, {auth_db, AuthDb}), - NewState#state{db_mon_ref = erlang:monitor(process, AuthDb#db.main_pid)}. + NewState#state{closed = [Ref|Closed], + db_mon_ref = erlang:monitor(process, AuthDb#db.main_pid)}. add_cache_entry(_, _, _, #state{max_cache_size = 0} = State) ->