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

fix(rax_tree): Fix crash caused by destructor in RaxTreeMap #4228

Conversation

BagritsevichStepan
Copy link
Contributor

@BagritsevichStepan BagritsevichStepan commented Nov 29, 2024

fixes #4172

The cause of the crash is double raxStop call: first time in the operator++ when raxNext returns false, second time in the destructor of the SeekIterator.

In this PR:

  1. Remove double raxStop call
  2. Fix bug when raxSeek returns 0 in the constructor
  3. Wrap iterator to optional for more safety
  4. Delete operator= for the SeekIterator
  5. Fixed operator== for the FindIterator. We had some strange logic there: if (this->has_value() != !bool(rhs.it_.flags & RAX_ITER_EOF))
  6. Add dcheks and logging for more safety

I also propose to change destructor of the RaxTreeMap. It should invoke raxFreeWithCallback. The problem is that this will require a capturing lambda, as we need to pass alloc_. Therefore, we need to copy and update the raxFreeWithCallback method for capturing lambdas.

@BagritsevichStepan
Copy link
Contributor Author

https://github.com/dragonflydb/dragonfly/actions/runs/12082557873

@romange
Copy link
Collaborator

romange commented Nov 29, 2024

Can you please explain what the problem is in the PR description?
i.e. the cause of crash is ..., this solution solves the problem by .... , but i suggest the following solution ...

@romange romange self-requested a review November 29, 2024 12:43
@BagritsevichStepan BagritsevichStepan force-pushed the df.search/fix-rax-tree-destructor branch from 104c9cf to 103d333 Compare December 3, 2024 12:41
@BagritsevichStepan
Copy link
Contributor Author

Can you please explain what the problem is in the PR description? i.e. the cause of crash is ..., this solution solves the problem by .... , but i suggest the following solution ...

Done

@BagritsevichStepan
Copy link
Contributor Author

@kostasrim Run it again: https://github.com/dragonflydb/dragonfly/actions/runs/12140115454

@BagritsevichStepan BagritsevichStepan changed the title fix(rax_tree): Fix crash caused by element destruction in RaxTreeMap fix(rax_tree): Fix crash caused by destructor in RaxTreeMap Dec 3, 2024
src/core/search/rax_tree.h Outdated Show resolved Hide resolved
src/core/search/rax_tree.h Outdated Show resolved Hide resolved
src/core/search/rax_tree.h Outdated Show resolved Hide resolved
@romange
Copy link
Collaborator

romange commented Dec 3, 2024

@BagritsevichStepan I agree that the interface of raxFreeWithCallback should be changed by accepting an additional void* arg argument that is passed by raxFreeWithCallback to each invocation of free_callback

@BagritsevichStepan BagritsevichStepan force-pushed the df.search/fix-rax-tree-destructor branch 3 times, most recently from cccc397 to b6de484 Compare December 4, 2024 15:03
Signed-off-by: Stepan Bagritsevich <[email protected]>
@BagritsevichStepan
Copy link
Contributor Author

BagritsevichStepan commented Dec 4, 2024

@romange I decided to introduce Callback calling in the another PR #4255. I'm not sure if we should merge this before the release

Copy link
Collaborator

@romange romange left a comment

Choose a reason for hiding this comment

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

LGTM

src/core/search/rax_tree.h Show resolved Hide resolved
@romange
Copy link
Collaborator

romange commented Dec 4, 2024

have you run on the traces you have to see it's working well?

@BagritsevichStepan
Copy link
Contributor Author

have you run on the traces you have to see it's working well?

Yes, https://github.com/dragonflydb/dragonfly/actions/runs/12162671806

@BagritsevichStepan BagritsevichStepan merged commit 81079df into dragonflydb:main Dec 4, 2024
10 checks passed
@BagritsevichStepan BagritsevichStepan deleted the df.search/fix-rax-tree-destructor branch December 4, 2024 17:34
romange pushed a commit that referenced this pull request Dec 10, 2024
* fix(rax_tree): Fix double raxStop call in the SeekIterator

fixes #4172

Signed-off-by: Stepan Bagritsevich <[email protected]>

* refactor(rax_tree): Address comments

Signed-off-by: Stepan Bagritsevich <[email protected]>

---------

Signed-off-by: Stepan Bagritsevich <[email protected]>
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.

Dragonfly crashes during RaxTreeMap::try_emplace
3 participants