Skip to content

Commit

Permalink
fix(csharp/src/Apache.Arrow.Adbc/C): finalizer threw exception (apach…
Browse files Browse the repository at this point in the history
…e#1842)

Allow imported objects to access a disposed driver when they themselves
are disposed, because finalization order is nondeterministic.

Closes apache#1817
  • Loading branch information
CurtHagenlocher authored May 8, 2024
1 parent 6238336 commit 0fe5383
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ internal unsafe ref CAdbcDriver Driver
}
}

internal unsafe ref CAdbcDriver DriverUnsafe
{
get
{
Debug.Assert(_references > 0);
return ref _nativeDriver;
}
}

internal ImportedAdbcDriver AddReference()
{
Interlocked.Increment(ref _references);
Expand Down Expand Up @@ -541,7 +550,7 @@ private unsafe void Dispose(bool disposing)
{
using (CallHelper caller = new CallHelper())
{
caller.Call(_driver.Driver.DatabaseRelease, ref _nativeDatabase);
caller.Call(_driver.DriverUnsafe.DatabaseRelease, ref _nativeDatabase);
}
}
}
Expand Down Expand Up @@ -819,7 +828,7 @@ private unsafe void Dispose(bool disposing)
{
using (CallHelper caller = new CallHelper())
{
caller.Call(_driver.Driver.ConnectionRelease, ref _nativeConnection);
caller.Call(_driver.DriverUnsafe.ConnectionRelease, ref _nativeConnection);
}
}
}
Expand Down Expand Up @@ -1065,7 +1074,7 @@ private unsafe void Dispose(bool disposing)
{
using (CallHelper caller = new CallHelper())
{
caller.Call(_driver.Driver.StatementRelease, ref _nativeStatement);
caller.Call(_driver.DriverUnsafe.StatementRelease, ref _nativeStatement);
}
}
}
Expand Down

0 comments on commit 0fe5383

Please sign in to comment.