Sfoglia il codice sorgente

ZOOKEEPER-981. Hang in zookeeper_close() in the multi-threaded C client. (Jeremy Stribling via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1170430 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar 13 anni fa
parent
commit
a7c483d16e
2 ha cambiato i file con 14 aggiunte e 2 eliminazioni
  1. 4 1
      CHANGES.txt
  2. 10 1
      src/c/src/zookeeper.c

+ 4 - 1
CHANGES.txt

@@ -313,7 +313,10 @@ BUGFIXES:
   ZOOKEEPER-731. Zookeeper#delete , #create - async versions miss a verb in the javadoc. (Thomas Koch via camille)
 
   ZOOKEEPER-1108. Various bugs in zoo_add_auth in C. (Dheeraj Agrawal via mahadev)
-  
+ 
+  ZOOKEEPER-981. Hang in zookeeper_close() in the multi-threaded C client. 
+  (Jeremy Stribling via mahadev) 
+
 IMPROVEMENTS:
   ZOOKEEPER-724. Improve junit test integration - log harness information 
   (phunt via mahadev)

+ 10 - 1
src/c/src/zookeeper.c

@@ -2471,15 +2471,24 @@ int zookeeper_close(zhandle_t *zh)
         return ZBADARGUMENTS;
 
     zh->close_requested=1;
-    if (inc_ref_counter(zh,0)!=0) {
+    if (inc_ref_counter(zh,1)>1) {
+        /* We have incremented the ref counter to prevent the
+         * completions from calling zookeeper_close before we have
+         * completed the adaptor_finish call below. */
+
 	/* Signal any syncronous completions before joining the threads */
         enter_critical(zh);
         free_completions(zh,1,ZCLOSING);
         leave_critical(zh);
 
         adaptor_finish(zh);
+        /* Now we can allow the handle to be cleaned up, if the completion
+         * threads finished during the adaptor_finish call. */
+        api_epilog(zh, 0);
         return ZOK;
     }
+    /* No need to decrement the counter since we're just going to
+     * destroy the handle later. */
     if(zh->state==ZOO_CONNECTED_STATE){
         struct oarchive *oa;
         struct RequestHeader h = { STRUCT_INITIALIZER (xid , get_xid()), STRUCT_INITIALIZER (type , ZOO_CLOSE_OP)};