Skip to content

Conversation

@paleolimbot
Copy link
Member

@paleolimbot paleolimbot commented Nov 30, 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

@github-actions github-actions bot added this to the ADBC Libraries 0.9.0 milestone Nov 30, 2023
@lidavidm lidavidm changed the title feat: Reference count child objects feat(r): Reference count child objects Nov 30, 2023
@paleolimbot paleolimbot marked this pull request as ready for review December 7, 2023 20:51
paleolimbot added a commit to apache/arrow-nanoarrow that referenced this pull request Dec 8, 2023
…y stream (#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 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 paleolimbot merged commit 595df25 into apache:main Dec 19, 2023
self_contained_finalizer <- function() {
try(adbc_release_non_null(x))
try({
parent$.child_count <- parent$.child_count - 1L
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this and other code be using adbc_update_parent_child_count() or a variant under the hood?


#include <utility>

#include <adbc.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this include is added here, should we remove it from some source files?

Copy link
Collaborator

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

I only skimmed over the code, we'll see how behavior improves when we use it.

@paleolimbot paleolimbot deleted the r-child-reference-count branch December 22, 2023 14:48
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.

Crash "bus error" with cause "invalid alignment"

2 participants