Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close on TTLDB causes segfault when destructing #4818

Open
adamretter opened this issue Dec 22, 2018 · 1 comment
Open

Close on TTLDB causes segfault when destructing #4818

adamretter opened this issue Dec 22, 2018 · 1 comment
Labels
bug Confirmed RocksDB bugs

Comments

@adamretter
Copy link
Collaborator

The following simple code will cause a segfault. ttl_db-test.cc:

#include <string>
#include "rocksdb/db.h"
#include "rocksdb/options.h"
#include "rocksdb/utilities/db_ttl.h"

using namespace rocksdb;

int main() {
  Options options;
  options.create_if_missing = true;
  
  DBWithTTL* ttl_db;
  Status s = DBWithTTL::Open(options, "test-ttl-db", &ttl_db);
  assert(s.ok());

  //TODO comment-out line below to avoid SIGSEGV
  ttl_db->Close();

  delete ttl_db;
}

Compile the above file inside a rocksdb git clone with:

$ DEBUG_LEVEL=2  make -j4 shared_lib
$ clang++ -std=c++11 -stdlib=libc++ -fpic -I include/ -o ttl_db-test librocksdb.dylib ttl_db-test.cc

Running the code above (./ttl_db-test) shows a segfault. The lldb trace is:

Process 50972 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    frame #0: 0x000000010014df6a librocksdb.5.18.dylib`rocksdb::DBImpl::GetOptions(this=0x0000000100cb7000, column_family=0x0000000100cbf480) const at db_impl.cc:2006 [opt]
   2003	  InstrumentedMutexLock l(&mutex_);
   2004	  auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
   2005	  return Options(BuildDBOptions(immutable_db_options_, mutable_db_options_),
-> 2006	                 cfh->cfd()->GetLatestCFOptions());
   2007	}
   2008
   2009	DBOptions DBImpl::GetDBOptions() const {
Target 0: (ttl_db-test) stopped.

The lldb backtrace is:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x000000010014df6a librocksdb.5.18.dylib`rocksdb::DBImpl::GetOptions(this=0x0000000100cb7000, column_family=0x0000000100cbf480) const at db_impl.cc:2006 [opt]
    frame #1: 0x0000000100330ef6 librocksdb.5.18.dylib`rocksdb::StackableDB::GetOptions(this=<unavailable>, column_family=<unavailable>) const at stackable_db.h:269 [opt]
    frame #2: 0x000000010011901f librocksdb.5.18.dylib`rocksdb::DB::GetOptions(this=0x0000000100cbf620) const at db.h:904 [opt]
    frame #3: 0x00000001003b94dc librocksdb.5.18.dylib`rocksdb::DBWithTTLImpl::~DBWithTTLImpl(this=0x0000000100cbf620) at db_ttl_impl.cc:41 [opt]
    frame #4: 0x00000001003b95ae librocksdb.5.18.dylib`rocksdb::DBWithTTLImpl::~DBWithTTLImpl() [inlined] rocksdb::DBWithTTLImpl::~DBWithTTLImpl(this=0x0000000100cbf620) at db_ttl_impl.cc:38 [opt]
    frame #5: 0x00000001003b95a9 librocksdb.5.18.dylib`rocksdb::DBWithTTLImpl::~DBWithTTLImpl(this=0x0000000100cbf620) at db_ttl_impl.cc:38 [opt]
    frame #6: 0x000000010000135c ttl_db-test`main + 508
    frame #7: 0x00007fff59c6508d libdyld.dylib`start + 1
@adamretter
Copy link
Collaborator Author

The problem seems to be that calling Close removes the options from the db, however the destructor of TTLDB wants to try and access the options. I am open to discussing how best to fix this...

@adamretter adamretter added the bug Confirmed RocksDB bugs label Dec 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed RocksDB bugs
Projects
None yet
Development

No branches or pull requests

1 participant