Copilot commented on code in PR #4983:
URL: https://github.com/apache/arrow-adbc/pull/4983#discussion_r4426148675


##########
csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverImporter.Streams.cs:
##########
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
+using Apache.Arrow.Adbc.Extensions;
+using Apache.Arrow.C;
+using Apache.Arrow.Ipc;
+
+namespace Apache.Arrow.Adbc.C
+{
+    public static partial class CAdbcDriverImporter
+    {
+        /// <summary>
+        /// A result stream imported from a driver. When the stream fails, it 
asks the driver
+        /// for the ADBC error behind the failure (see 
<c>AdbcErrorFromArrayStream</c>) and
+        /// throws it as an <see cref="AdbcException"/>.
+        /// </summary>
+        private sealed unsafe class ImportedArrayStream : IArrowArrayStream
+        {
+            private readonly ImportedAdbcDriver? _driver;
+            private readonly Schema _schema;
+            private CArrowArrayStream* _cStream;

Review Comment:
   Unlike the database, connection, and statement wrappers, this stream stores 
`_driver` without taking an `AddReference`. `ExecuteQuery` returns the stream 
after its `CallHelper` is disposed, so a caller can dispose the statement and 
driver before consuming the stream; the driver's reference count can then reach 
zero and unload/release the native driver. A later failing read calls 
`DriverUnsafe.ErrorFromArrayStream` through that released state (and stream 
cleanup can likewise use invalid callbacks). Retain a driver reference when the 
stream is successfully created and release it from `Dispose`/the finalizer, 
with rollback if schema import fails.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to