facebook / facebook/rocksdb

Close on TTLDB causes segfault when destructing

Open
#4,818 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
32.1k
Forks
6.9k
Avg merge
32m
Merged PRs (30d)
1

Description

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

```C++
#include
#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(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=, column_family=) 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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.