From 5709e97a74000ea688408289a17a1abf17990150 Mon Sep 17 00:00:00 2001 From: Maysam Yabandeh Date: Tue, 7 Jan 2020 15:33:05 -0800 Subject: [PATCH] Skip CancelAllBackgroundWork if DBImpl is already closed (#6268) Summary: WritePreparedTxnDB calls CancelAllBackgroundWork in its destructor to avoid dangling references to it from background job's SnapshotChecker callback. However, if the DBImpl is already closed, the info log might be closed with it, which causes memory leak when CancelAllBackgroundWork tries to print to the info log. The patch fixes that by calling CancelAllBackgroundWork only if the db is not closed already. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6268 Differential Revision: D19303439 Pulled By: maysamyabandeh fbshipit-source-id: 4228a6be7e78d43c90630347baa89b008200bd15 --- utilities/transactions/write_prepared_txn_db.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utilities/transactions/write_prepared_txn_db.cc b/utilities/transactions/write_prepared_txn_db.cc index 504541ba0..f399ea99d 100644 --- a/utilities/transactions/write_prepared_txn_db.cc +++ b/utilities/transactions/write_prepared_txn_db.cc @@ -970,7 +970,9 @@ WritePreparedTxnDB::~WritePreparedTxnDB() { // At this point there could be running compaction/flush holding a // SnapshotChecker, which holds a pointer back to WritePreparedTxnDB. // Make sure those jobs finished before destructing WritePreparedTxnDB. - db_impl_->CancelAllBackgroundWork(true /*wait*/); + if (!db_impl_->shutting_down_) { + db_impl_->CancelAllBackgroundWork(true /*wait*/); + } } void SubBatchCounter::InitWithComp(const uint32_t cf) {