facebook / facebook/rocksdb

Iterator crashes JVM on closed database (RocksJava)

Open
#5,234 5 comments 0 reactions 1 assignee Claimed by @adamretter View on GitHub
java-api
Dominant language
C++
Stars
32.1k
Forks
6.9k
Avg merge
32m
Merged PRs (30d)
1

Description

This bug report is for RocksJava JNI wrapper (any recent version).

After closing the database object, if we try to read an iterator associated with the closed database, the JVM crashes. I'm not sure this is by design or the expected behavior would be a null or something like an `IllegalStateException`. In my application, I call the iterator's `isValid()` method right before reading the iterator, but the JVM crash still happens because of a race condition where the database is closed in another thread.

### Expected behavior

Throw an `IllegalStateException`? Return `null`? Or users are expected to always synchronize all iterator accesses on the RocksDB database object?

### Actual behavior

JVM crashes:

```
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f94c174b979, pid=23521, tid=0x00007f956e988700
#
# JRE version: OpenJDK Runtime Environment (8.0_191-b12) (build 1.8.0_191-8u191-b12-2ubuntu0.16.04.1-b12)
# Java VM: OpenJDK 64-Bit Server VM (25.191-b12 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [librocksdbjni4452423069810647234.so+0x374979] rocksdb::MemTableIterator::value() const+0x19
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/username/workspace/myapp/hs_err_pid23521.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
```

### Steps to reproduce the behavior

The following test case crashes the JVM.

```java
static {
RocksDB.loadLibrary();
}

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

@Test
public void shouldCrashJavaRocks() throws IOException, RocksDBException {
String path = tempFolder.newFolder().toString();
Options options = new Options();
options.setCreateIfMissing(true);
RocksDB db = RocksDB.open(options, path);
byte[] key = {0x1};
byte[] value = {0x2};
db.put(key, value);

RocksIterator it = db.newIterator();
db.close();

assertFalse(it.isValid());

it.value(); // crashes the JVM
}
```

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.