alberttwong opened a new issue, #5039:
URL: https://github.com/apache/arrow-adbc/issues/5039

   ### What happened?
   
   After a Flight SQL server outage, Cursor.close() reports the expected 
ClosePreparedStatement transport error, but retrying close (or Cursor.__del__) 
raises RuntimeError: Underflow in closing this AdbcStatement. This also occurs 
after fully fetching the result, so it is independent of unread streams. 
Expected: a release failure must not make repeated cleanup decrement the 
connection child count again.
   
   In the installed _lib.pyx, AdbcStatement.close() calls 
self.connection._close_child() before checking statement.private_data and 
before AdbcStatementRelease succeeds. DB-API Cursor.close() sets _closed only 
after statement.close() returns. This appears to explain the double decrement; 
this diagnosis is not a tested patch.
   
   Related: #1912 contains the same underflow in a comment, but its main report 
concerns a PostgreSQL query hang. This report isolates Python cleanup 
bookkeeping independently of that query/parameter behavior. Found while 
qualifying redis/redis-dbt-adapter#40 and redis/redis-dbt-adapter#58. The 
adapter stream lifecycle was fixed separately; genuine server-outage cleanup 
still fails.
   
   ### Stack Trace
   
   First close:
   ```text
   OperationalError IO: [FlightSQL] connection error: desc = "transport: Error 
while dialing: dial tcp 127.0.0.1:18842: connect: connection refused" 
(Unavailable; ClosePreparedStatement). Vendor code: 14
   ```
   Second close:
   ```text
   RuntimeError: Underflow in closing this AdbcStatement
   ```
   Destructor:
   ```text
   Exception ignored in: <function Cursor.__del__>
     File "adbc_driver_manager/dbapi.py", line 1053, in __del__
       self.close()
     File "adbc_driver_manager/dbapi.py", line 851, in close
       self._stmt.close()
     File "adbc_driver_manager/_lib.pyx", line 1554, in AdbcStatement.close
     File "adbc_driver_manager/_lib.pyx", line 330, in _AdbcHandle._close_child
   RuntimeError: Underflow in closing this AdbcStatement
   ```
   
   ### How can we reproduce the bug?
   
   Start a prepared-statement-capable Flight SQL server. The local reproduction 
launched a dedicated owned server subprocess, then executed:
   
   ```python
   import adbc_driver_flightsql.dbapi as flight
   conn = flight.connect(FLIGHT_URI, db_kwargs=OPTIONS, autocommit=True)
   cur = conn.cursor()
   cur.execute("SELECT 1 AS value")
   assert cur.fetchall() == [(1,)]
   
   server.kill()
   server.wait(timeout=10)
   
   for attempt in range(2):
       try:
           cur.close()
       except Exception as exc:
           print(attempt + 1, type(exc).__name__, str(exc))
   conn.close()
   ```
   
   FLIGHT_URI, OPTIONS and server are deployment-specific connection settings 
and the subprocess handle. The local fault injection was executed, including 
fetching all rows before terminating the server and waiting for it to exit. 
First close: OperationalError; second close: handle underflow; connection close 
succeeds; destructor emits an ignored underflow. No private credentials are 
included.
   
   ### Environment/Setup
   
   macOS arm64; Python 3.13.16; PyArrow 26.0.0; adbc-driver-manager 1.13.0; 
adbc-driver-flightsql 1.13.0.
   
   Authenticated TLS Redis-backed Flight server: 
redis/redis-apache-arrow-flight@4d91e37135080be7f0eeb770fc89fa7adeb14bc8, built 
with Redis ADBC v0.0.27 (225e00569986e8340acd5978345f3275a889ade6). Installed 
Python packages with uv/pip.
   
   This report was drafted with an AI assistant; the described local 
fault-injection reproduction was executed.


-- 
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