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

[C++] Fix ManagedQuery segv: ctor/dtor order fix #3544

Merged
merged 6 commits into from
Jan 10, 2025

Conversation

bkmartinjr
Copy link
Member

@bkmartinjr bkmartinjr commented Jan 10, 2025

Issue and/or context:

But reported via chanzuckerberg/cellxgene-census#1327 - root cause was incorrect destructor ordering in the new ManagedQuery class.

The tiledb::Array class requires a tiledb::Context to destruct, but only holds a std::reference_wrapper<Context>. It is holder's responsibility to ensure that the Array's context is alive when the array is destructed.

ManagedQuery just had the context and array shared pointers in the wrong order, causing the context to destruct first in some cases.

[sc-61614]

Changes:

Change declaration order of members, thereby correctly ordering the dtor calls.

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.32%. Comparing base (4d536c7) to head (e44c249).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3544      +/-   ##
==========================================
+ Coverage   86.27%   86.32%   +0.04%     
==========================================
  Files          55       55              
  Lines        6369     6369              
==========================================
+ Hits         5495     5498       +3     
+ Misses        874      871       -3     
Flag Coverage Δ
python 86.32% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
python_api 86.32% <ø> (+0.04%) ⬆️
libtiledbsoma ∅ <ø> (∅)

@bkmartinjr bkmartinjr marked this pull request as ready for review January 10, 2025 02:59
mq = X.read().tables()
return mq

for _ in range(100):
Copy link
Member

Choose a reason for hiding this comment

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

Is this loop here because the error is intermittent?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not intermittent in my setup. But Python doesn't give any real guarantees about GC behavior, so it is possible that multiple calls might be required to trip over it in some Python implementation. I was just being cautious - trying to be triple-sure we would eventually trigger GC of the reference holders

Copy link
Member

Choose a reason for hiding this comment

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

Please leave a code comment to that effect within the test case -- otherwise future readers may be puzzled ...

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@johnkerl johnkerl changed the title [C++] Fix ManagedQuery segv: ctor/dtor order fix [C++] Fix ManagedQuery segv: ctor/dtor order fix Jan 10, 2025
@bkmartinjr bkmartinjr merged commit 4d3e4b6 into main Jan 10, 2025
16 checks passed
@bkmartinjr bkmartinjr deleted the bkmartinjr/mq-destructor-order branch January 10, 2025 16:00
github-actions bot pushed a commit that referenced this pull request Jan 10, 2025
* ctor/dtor order fix

* lint

* add comments

* lint

* add test case

* add commnet
johnkerl pushed a commit that referenced this pull request Jan 10, 2025
* ctor/dtor order fix

* lint

* add comments

* lint

* add test case

* add commnet

Co-authored-by: Bruce Martin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants