Author: phunt
Date: Wed May  5 22:00:50 2010
New Revision: 941513

URL: http://svn.apache.org/viewvc?rev=941513&view=rev
Log:
ZOOKEEPER-763. Deadlock on close w/ zkpython / c client

Added:
    
hadoop/zookeeper/branches/branch-3.3/src/contrib/zkpython/src/test/close_deadlock_test.py
Modified:
    hadoop/zookeeper/branches/branch-3.3/CHANGES.txt
    hadoop/zookeeper/branches/branch-3.3/src/contrib/zkpython/src/c/zookeeper.c

Modified: hadoop/zookeeper/branches/branch-3.3/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.3/CHANGES.txt?rev=941513&r1=941512&r2=941513&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.3/CHANGES.txt (original)
+++ hadoop/zookeeper/branches/branch-3.3/CHANGES.txt Wed May  5 22:00:50 2010
@@ -38,6 +38,9 @@ BUGFIXES:
 
   ZOOKEEPER-737. some 4 letter words may fail with netcat (nc) (mahadev)
 
+  ZOOKEEPER-763. Deadlock on close w/ zkpython / c client
+  (henry via phunt)
+
 Release 3.3.0 - 2010-03-24
 
 Non-backward compatible changes:

Modified: 
hadoop/zookeeper/branches/branch-3.3/src/contrib/zkpython/src/c/zookeeper.c
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.3/src/contrib/zkpython/src/c/zookeeper.c?rev=941513&r1=941512&r2=941513&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.3/src/contrib/zkpython/src/c/zookeeper.c 
(original)
+++ hadoop/zookeeper/branches/branch-3.3/src/contrib/zkpython/src/c/zookeeper.c 
Wed May  5 22:00:50 2010
@@ -1258,12 +1258,15 @@ PyObject *pyzoo_set_acl(PyObject *self, 
 /* Closes a connection, returns integer error code */
 PyObject *pyzoo_close(PyObject *self, PyObject *args)
 {
-  int zkhid;
+  int zkhid, ret;
   if (!PyArg_ParseTuple(args, "i", &zkhid)) {
     return NULL;
   }
   CHECK_ZHANDLE(zkhid);
-  int ret = zookeeper_close(zhandles[zkhid]);
+  zhandle_t *handle = zhandles[zkhid];
+  Py_BEGIN_ALLOW_THREADS
+  ret = zookeeper_close(handle);
+  Py_END_ALLOW_THREADS
   zhandles[zkhid] = NULL; // The zk C client frees the zhandle
   return Py_BuildValue("i", ret);
 }

Added: 
hadoop/zookeeper/branches/branch-3.3/src/contrib/zkpython/src/test/close_deadlock_test.py
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.3/src/contrib/zkpython/src/test/close_deadlock_test.py?rev=941513&view=auto
==============================================================================
--- 
hadoop/zookeeper/branches/branch-3.3/src/contrib/zkpython/src/test/close_deadlock_test.py
 (added)
+++ 
hadoop/zookeeper/branches/branch-3.3/src/contrib/zkpython/src/test/close_deadlock_test.py
 Wed May  5 22:00:50 2010
@@ -0,0 +1,50 @@
+#!/usr/bin/python
+#
+#  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.
+
+import zookeeper, zktestbase, unittest, threading
+import time
+
+
+class CloseDeadlockTest(zktestbase.TestBase):
+  """
+  This tests for the issue found in
+  https://issues.apache.org/jira/browse/ZOOKEEPER-763
+
+  zookeeper.close blocks on waiting for all completions to
+  finish. Previously it was doing so while holding teh GIL, stopping
+  any completions from actually continuing.
+
+  This test is a failure if it does not exit within a few seconds.
+  """
+  def deadlock():
+    cv = threading.Condition()
+
+    def callback(*args):
+        cv.acquire()
+        cv.notifyAll()
+        cv.release()
+        time.sleep(1)
+
+    cv.acquire()
+    zookeeper.aget(handle, "/", None, callback)
+    cv.wait()
+    zookeeper.close(handle)
+
+
+if __name__ == '__main__':
+  unittest.main()


Reply via email to