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

Prevent rocksdb segfaults when accessing closed storage #5527

Merged
merged 7 commits into from
Jun 2, 2023

Conversation

garyschulte
Copy link
Contributor

@garyschulte garyschulte commented Jun 1, 2023

PR description

gate transaction access on whether the underlying storage has closed. This prevents segfaults at shutdown when we close rocksdb, but there are async processes attempting to access the db.

Currently evaluating to ensure there is no noticeable performance regression.

Fixed Issue(s)

#5362

@github-actions
Copy link

github-actions bot commented Jun 1, 2023

  • I thought about documentation and added the doc-change-required label to this PR if updates are required.
  • I thought about the changelog and included a changelog update if required.
  • If my PR includes database changes (e.g. KeyValueSegmentIdentifier) I have thought about compatibility and performed forwards and backwards compatibility tests

@garyschulte garyschulte changed the title Bugfix/5362 tx safety Prevent rocksdb segfaults when accessing closed storage Jun 2, 2023
Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, couple of nits

@@ -114,4 +114,11 @@ public interface KeyValueStorage extends Closeable {
* @throws StorageException problem encountered when starting a new transaction.
*/
KeyValueStorageTransaction startTransaction() throws StorageException;

/**
* Return Whether the underlying storage is closed or not.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Return Whether the underlying storage is closed or not.
* Return Whether the underlying storage is closed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

private void throwIfClosed() {
if (parent.isClosed()) {
LOG.error("Attempting to use a closed RocksDBKeyValueStorage");
throw new IllegalStateException("Storage has been closed");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RocksDBSnapshotTransaction uses StorageException - does it make sense to match that here?
throw new StorageException("Storage has already been closed");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think storage exception is better everywhere possible 👍

…hutdown

Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
… in debug

Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
@garyschulte garyschulte merged commit b401963 into hyperledger:main Jun 2, 2023
@garyschulte garyschulte deleted the bugfix/5362-tx-safety branch June 2, 2023 18:39
elenduuche pushed a commit to elenduuche/besu that referenced this pull request Aug 16, 2023
…5527)

* add isClosed check to Transaction decorator to prevent segfaults on shutdown

Signed-off-by: garyschulte <garyschulte@gmail.com>
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
…5527)

* add isClosed check to Transaction decorator to prevent segfaults on shutdown

Signed-off-by: garyschulte <garyschulte@gmail.com>
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 this pull request may close these issues.

2 participants