Skip to content

Conversation

@paleolimbot
Copy link
Member

Uncovered when investigating apache/arrow-adbc#1348 and apache/arrow-adbc#1334 . Before, the release callback was getting called by the garbage collector (so no memory leak was reported); however, the order of the array stream finalizer and the user-supplied R finalizer was non-deterministic based on when the garbage collector ran.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a53e70b) 88.04% compared to head (78acb5c) 88.03%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #333      +/-   ##
==========================================
- Coverage   88.04%   88.03%   -0.01%     
==========================================
  Files          72       68       -4     
  Lines       11369    11269     -100     
==========================================
- Hits        10010     9921      -89     
+ Misses       1359     1348      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@paleolimbot paleolimbot merged commit f82a6d7 into apache:main Dec 8, 2023
@paleolimbot paleolimbot deleted the r-wrapper-array-stream-release branch December 8, 2023 00:05
paleolimbot added a commit to paleolimbot/arrow-nanoarrow that referenced this pull request Dec 8, 2023
…y stream (apache#333)

Uncovered when investigating
apache/arrow-adbc#1348 and
apache/arrow-adbc#1334 . Before, the release
callback was getting called by the garbage collector (so no memory leak
was reported); however, the order of the array stream finalizer and the
user-supplied R finalizer was non-deterministic based on when the
garbage collector ran.
paleolimbot added a commit to apache/arrow-adbc that referenced this pull request Dec 19, 2023
This PR adds a `.child_count` for all database, connection, and
statement objects to ensure that we do not call the C-level release
callback while a child object is available.

Since very early commits, we had set `R_ExternalPtrProtected()` to the
parent object, which meant that if you never called
`adbc_XXX_release()`, R would correctly sort out the object dependencies
and call the release callbacks in the correct order.

One major exception to that was the returned `ArrowArrayStream`
wrappers, for which there was no mechanism to add a dependent SEXP until
I added it (in nanoarrow 0.2, I think); however, it wasn't actually used
for anything except for the stream returned by `read_adbc()`.

@nbenn / @krlmlr you are probably the best candidates to give this a
review/ensure that it fixes or makes it easier to debug the issues you
have been having in adbi! Note that
apache/arrow-nanoarrow#333 may have been the
primary culprit (I will push that out to CRAN ASAP as a tweak release).

Closes apache/arrow-nanoarrow#323 ,
#1128 . Perhaps related:
#1348 .

I triggered some extended checks as well (as they include valgrind):
https://github.com/paleolimbot/arrow-adbc/actions/runs/7133874110
@paleolimbot paleolimbot added this to the nanoarrow 0.4.0 milestone Jan 26, 2024
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