Fix CouchDB operations after close and add test.