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

Thread safety of WriteBatch object not synchronized #6

Closed
braydonf opened this issue Sep 27, 2019 · 2 comments · Fixed by #7
Closed

Thread safety of WriteBatch object not synchronized #6

braydonf opened this issue Sep 27, 2019 · 2 comments · Fixed by #7

Comments

@braydonf
Copy link
Contributor

There is a memory safety issue when making batch database calls.

Details:

Within a single process, the same leveldb::DB object may be safely shared by multiple concurrent threads. (...) However other objects (like Iterator and WriteBatch) may require external synchronization. If two threads share such an object, they must protect access to it using their own locking protocol. (...)

https://github.com/google/leveldb/blob/master/doc/index.md#concurrency

The bindings (./src/bindings.cc) methods batch_init, batch_put, batch_del, batch_write and batch_clear all share access to the WriteBatch object. The batch_write method will share the object with another thread in BatchWriteWorker. It's possible that batch_put, batch_del and batch_clear can unsafely modify the WriteBatch object that is shared with the other thread.

Reproduce:

Call batch_put, batch_del or batch_clear after a call to batch_write and before the batch_write worker thread is complete.

Some of the possible errors:

  • Segmentation fault
  • Abort trap 6
  • Corruption: unknown WriteBatch tag
  • Corruption: bad WriteBatch Put
  • Corruption: WriteBatch has wrong count
@braydonf
Copy link
Contributor Author

It can also be reproduced by calling db_close after batch_write and before the worker thread is complete. This can be seen, as with the other cases, in the pull request at #7.

@braydonf
Copy link
Contributor Author

Also related bcoin-org/bcoin#864

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant