[omniORB] [patch] fix omniOTS deadlock

Luke Deller ldeller at xplantechnology.com
Fri Mar 18 17:04:11 GMT 2005


Hi Scott,

Using gdb I was able to locate the cause of the deadlock I have been experiencing in a python omniOTS client.  Some code in omniOTS/python/pyomniOTS.cc was trying to release a CORBA objref while holding the python lock.  This practice can produce a deadlock - there's a brief explanation in the omniORBpy 1.3 bugfix list (see "bug number 3"):

http://omniorb.sourceforge.net/pybugs/bugfixes13.html#bug3

Attached is a patch to fix this problem in omniOTS (plus it fixes two gcc-3.4 warnings in the same source file).

Regards,
Luke.

-------------- next part --------------
--- omniOTS_sf/python/pyomniOTS.cc	2005-03-15 11:28:15.169057816 +1100
+++ omniOTS/python/pyomniOTS.cc	2005-03-18 16:22:08.828634870 +1100
@@ -90,7 +90,7 @@
 PyObject*
 createPyTXNCurrentObject(const CORBA::Object_ptr objref) {
 
-  Current_var pc = Current::_narrow(objref);
+  Current_ptr pc = Current::_narrow(objref);
 
   if (CORBA::is_nil(pc)) {
     return 0;
@@ -292,11 +292,11 @@
     if (!PyArg_ParseTuple(args, "O&i", objToCurrent, &current_txn, &report))
       return 0;
 
-    report_heuristics = report;
+    report_heuristics = !!report;
      
     try {
       InterpreterUnlocker _u;
-      current_txn->commit(report);
+      current_txn->commit(report_heuristics);
     }
     CATCH_AND_HANDLE_SYSTEM_EXCEPTIONS
     
@@ -407,7 +407,8 @@
   static PyObject* pyTXN_get_control(PyObject* self, PyObject* args)
   {
     Current_ptr current_txn=0;
-    Control_var control;
+    Control_ptr control;
+    PyObject* result;
     
     if (!PyArg_ParseTuple(args, "O&", objToCurrent, &current_txn))
       return 0;
@@ -415,10 +416,12 @@
     try {
       InterpreterUnlocker _u;
       control  = current_txn->get_control();
+      result = omniAPI->cxxObjRefToPyObjRef(control, 0);
+      CORBA::release(control);
     }
     CATCH_AND_HANDLE_SYSTEM_EXCEPTIONS
 
-    return omniAPI->cxxObjRefToPyObjRef(control, 1);
+    return result;
     //omniPy::createPyCorbaObjRef(control->_PD_repoId, control);
   }
 
@@ -426,18 +429,20 @@
   {
     Current_ptr current_txn=0;
     Control_ptr control;
+    PyObject* result;
     
     if (!PyArg_ParseTuple(args, "O&", objToCurrent, &current_txn))
       return 0;
 
     try {
       InterpreterUnlocker _u;
-      control  = current_txn->suspend();
-
+      control = current_txn->suspend();
+      result = omniAPI->cxxObjRefToPyObjRef(control, 0);
+      CORBA::release(control);
     }
     CATCH_AND_HANDLE_SYSTEM_EXCEPTIONS
 
-    return omniAPI->cxxObjRefToPyObjRef(control, 1);
+    return result;
     //omniPy::createPyCorbaObjRef(control->_PD_repoId, control);
   }
 
@@ -450,18 +455,24 @@
       return 0;
     
     try {
-      CORBA::Object_var obj;
-      Control_var    control;
+      CORBA::Object_ptr obj;
 
       obj = omniAPI->pyObjRefToCxxObjRef(pycontrol, 1);
 
       {
 	InterpreterUnlocker _u;
-	control = Control::_narrow(obj);
-	current_txn->resume(control);
+	try {
+	  Control_var control;
+	  control = Control::_narrow(obj);
+	  current_txn->resume(control);
+	} catch (...) {
+	  CORBA::release(obj);
+	  throw;
+	}
+	CORBA::release(obj);
       }
     }
-    catch (CORBA::BAD_PARAM& ex) {
+    catch (CORBA::BAD_PARAM&) {
       PyErr_SetString(PyExc_TypeError,
 		      (char*)"resume() expects a Control as its argument");
       return 0;


More information about the omniORB-list mailing list