maggma icon indicating copy to clipboard operation
maggma copied to clipboard

Possible Issue with store.close() when using SSHTunnel

Open sivonxay opened this issue 4 years ago • 0 comments

See example below for context. Not sure if this is intended behavior or a bug, since forcing a reconnect fixes the issue.

from maggma.stores.mongolike import MongoStore

store = MongoStore(<credentials/etc here>) 
store.connect()
store.query_one({}) # This works fine and has no issues
store.close()

# Since MongoStore.close() does not clear the MongoStore._collection variable, calling connect() does nothing
store.connect() 
# This query is fine if SSHTunnels are not in use, since the connection to the DB is 
# automatically reopened by MongoClient. If SSHTunnel is used, the connection to 
# the not work, since the SSHTunnel connection was already closed
test_doc = store.query_one({})  

# This works, as the connection to the SSHTunnel is re-established
store.connect(force_reset=True) 
test_doc = store.query_one({}) 

sivonxay avatar Oct 07 '21 01:10 sivonxay