Avoid deadlock when deleting/shutdown database

backport fix from
couchbase/couchdb#dbebcf91442d999409b1cde67d49b6f45cb7506b