This is an automated email from the ASF dual-hosted git repository.

jiangphcn pushed a commit to branch 
COUCHDB-3326-clustered-purge-pr1-misc-cleanup
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit bb27d5ebb02a1034bf4e0b5c33c1ba3189d5f9b1
Author: Paul J. Davis <[email protected]>
AuthorDate: Thu Apr 26 11:39:58 2018 -0500

    Fix race on couch_db:reopen/1
    
    This fixes a minor race by opening the database before closing it. This
    was never found to be an issue in production and was just caught while
    contemplating the PSE test suite.
---
 src/couch/src/couch_db.erl | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index 65ca54a..40c673a 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -161,8 +161,11 @@ reopen(#db{} = Db) ->
     % We could have just swapped out the storage engine
     % for this database during a compaction so we just
     % reimplement this as a close/open pair now.
-    close(Db),
-    open(Db#db.name, [{user_ctx, Db#db.user_ctx} | Db#db.options]).
+    try
+        open(Db#db.name, [{user_ctx, Db#db.user_ctx} | Db#db.options])
+    after
+        close(Db)
+    end.
 
 
 % You shouldn't call this. Its part of the ref counting between

Reply via email to