This is an automated email from the ASF dual-hosted git repository.
curth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new 003f5e640 fix(csharp/src/Client): Fix some resource management in
`AdbcDataReader` (#4134)
003f5e640 is described below
commit 003f5e640cade5ea974023ce16ef3ce1ccb7c860
Author: Curt Hagenlocher <[email protected]>
AuthorDate: Sun Mar 29 10:26:14 2026 -0700
fix(csharp/src/Client): Fix some resource management in `AdbcDataReader`
(#4134)
Fixes a few small issues I noticed while reviewing a change recently.
---
csharp/src/Client/AdbcDataReader.cs | 24 +++++++++-------------
.../Client/DuckDbClientTests.cs | 13 +++++++-----
2 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/csharp/src/Client/AdbcDataReader.cs
b/csharp/src/Client/AdbcDataReader.cs
index 7b85875bb..1b7ac02f2 100644
--- a/csharp/src/Client/AdbcDataReader.cs
+++ b/csharp/src/Client/AdbcDataReader.cs
@@ -134,13 +134,7 @@ namespace Apache.Arrow.Adbc.Client
public override void Close()
{
- if (this.closeConnection)
- {
- this.adbcCommand?.Connection?.Close();
- }
- this.adbcQueryResult.Stream?.Dispose();
- this.adbcQueryResult.Stream = null;
- this.isClosed = true;
+ this.Dispose(disposing: true);
}
public override bool GetBoolean(int ordinal)
@@ -308,13 +302,6 @@ namespace Apache.Arrow.Adbc.Client
public override bool NextResult()
{
- this.recordBatch = ReadNextRecordBatchAsync().Result;
-
- if (this.recordBatch != null)
- {
- return true;
- }
-
return false;
}
@@ -322,8 +309,16 @@ namespace Apache.Arrow.Adbc.Client
{
if (disposing)
{
+ if (this.closeConnection)
+ {
+ this.adbcCommand?.Connection?.Close();
+ }
+
this.recordBatch?.Dispose();
this.recordBatch = null;
+ this.adbcQueryResult.Stream?.Dispose();
+ this.adbcQueryResult.Stream = null;
+ this.isClosed = true;
}
}
@@ -339,6 +334,7 @@ namespace Apache.Arrow.Adbc.Client
// If ReadNextRecordBatchAsync throws (e.g. server error
mid-stream),
// callers that retry Read() must not re-read stale rows from the
// old batch — they must see the exception again immediately.
+ this.recordBatch?.Dispose();
this.recordBatch = null;
this.recordBatch = ReadNextRecordBatchAsync().Result;
diff --git a/csharp/test/Apache.Arrow.Adbc.Tests/Client/DuckDbClientTests.cs
b/csharp/test/Apache.Arrow.Adbc.Tests/Client/DuckDbClientTests.cs
index 0e183ec1c..860c05ce9 100644
--- a/csharp/test/Apache.Arrow.Adbc.Tests/Client/DuckDbClientTests.cs
+++ b/csharp/test/Apache.Arrow.Adbc.Tests/Client/DuckDbClientTests.cs
@@ -139,13 +139,16 @@ namespace Apache.Arrow.Adbc.Tests.Client
command.Parameters[1].DbType = DbType.String;
command.Parameters[1].Value = "foo";
- using var reader = command.ExecuteReader();
- long count = 0;
- while (reader.Read())
+ using (var reader =
command.ExecuteReader(CommandBehavior.CloseConnection))
{
- count++;
+ long count = 0;
+ while (reader.Read())
+ {
+ count++;
+ }
+ Assert.Equal(1, count);
}
- Assert.Equal(1, count);
+ Assert.True(connection.State == ConnectionState.Closed);
}
private static long GetResultCount(AdbcCommand command, string query)