Copilot commented on code in PR #50687:
URL: https://github.com/apache/arrow/pull/50687#discussion_r3674428888


##########
python/pyarrow/src/arrow/python/flight.cc:
##########
@@ -86,6 +86,12 @@ PyFlightServer::PyFlightServer(PyObject* server, const 
PyFlightServerVtable& vta
   server_.reset(server);
 }
 
+void PyFlightServer::ReleasePythonServerRef() {
+  // Resets OwnedRefNoGIL to break the reference cycle between the C++ 
FlightServerBase
+  // and the Python object.
+  server_.reset();
+}

Review Comment:
   ReleasePythonServerRef() calls OwnedRefNoGIL::reset(), which ultimately does 
Py_XDECREF without acquiring the GIL (see OwnedRef::reset in 
arrow/python/common.h). Since this method is declared in a `nogil` Cython 
extern block, it is easy to call it while the GIL is not held, leading to 
undefined behavior / crashes. Make ReleasePythonServerRef acquire the GIL when 
needed (and avoid DECREF when the interpreter is finalized).



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