ZooKeeper
  1. ZooKeeper
  2. ZOOKEEPER-591

The C Client cannot exit properly in some situation

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 3.2.1
    • Fix Version/s: 3.3.0
    • Component/s: c client
    • Labels:
      None
    • Environment:

      Linux db-passport-test05.vm 2.6.9_5-4-0-5 #1 SMP Tue Apr 14 15:56:24 CST 2009 x86_64 x86_64 x86_64 GNU/Linux

    • Hadoop Flags:
      Reviewed
    • Tags:
      Zookeeper C Client

      Description

      The following code produce a situation, where the C Client can not exit properly,

      #include "include/zookeeper.h"

      void default_zoo_watcher(zhandle_t zzh, int type, int state, const char *path, void context){
      int zrc = 0;
      struct String_vector str_vec =

      {0, NULL};
      printf("in the default_zoo_watcher\n");
      zrc = zoo_wget_children(zzh, "/mytest", default_zoo_watcher, NULL, &str_vec);
      printf("zoo_wget_children, error: %d\n", zrc);

      return;
      }

      int main()
      {
      int zrc = 0;
      int buff_len = 10;
      char buff[10] = "hello";
      char path[512];
      struct Stat stat;
      struct String_vector str_vec = {0, NULL}

      ;

      zhandle_t *zh = zookeeper_init("10.81.20.62:2181", NULL, 30000, 0, 0, 0);
      zrc = zoo_create(zh, "/mytest", buff, 10, &ZOO_OPEN_ACL_UNSAFE, 0, path, 512);
      printf("zoo_create, error: %d\n", zrc);

      zrc = zoo_wget_children(zh, "/mytest", default_zoo_watcher, NULL, &str_vec);
      printf("zoo_wget_children, error: %d\n", zrc);

      zrc = zoo_create(zh, "/mytest/test1", buff, 10, &ZOO_OPEN_ACL_UNSAFE, 0, path, 512);
      printf("zoo_create, error: %d\n", zrc);

      zrc = zoo_wget_children(zh, "/mytest", default_zoo_watcher, NULL, &str_vec);
      printf("zoo_wget_children, error: %d\n", zrc);

      zrc = zoo_delete(zh, "/mytest/test1", -1);

      printf("zoo_delete, error: %d\n", zrc);
      zookeeper_close(zh);
      return 0;
      }

      running this code can cause the program hang at zookeeper_close(zh);(line 38). using gdb to attach the process, I found that the main thread is waiting for do_completion thread to finish,
      (gdb) bt
      #0 0x000000302b806ffb in pthread_join () from /lib64/tls/libpthread.so.0
      #1 0x000000000040de3b in adaptor_finish (zh=0x515b60) at src/mt_adaptor.c:219
      #2 0x00000000004060ba in zookeeper_close (zh=0x515b60) at src/zookeeper.c:2100
      #3 0x000000000040220b in main ()

      and the thread which handle the zoo_wget_children(in the default_zoo_watcher) is waiting for sc->cond.
      (gdb) thread 2
      [Switching to thread 2 (Thread 1094719840 (LWP 25093))]#0 0x000000302b8089aa in pthread_cond_wait@@GLIBC_2.3.2 ()
      from /lib64/tls/libpthread.so.0
      (gdb) bt
      #0 0x000000302b8089aa in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/tls/libpthread.so.0
      #1 0x000000000040d88b in wait_sync_completion (sc=0x5167f0) at src/mt_adaptor.c:82
      #2 0x00000000004082c9 in zoo_wget_children (zh=0x515b60, path=0x40ebc0 "/mytest", watcher=0x401fd8 <default_zoo_watcher>, watcherCtx=Variable "watcherCtx" is not available.)
      at src/zookeeper.c:2884
      #3 0x0000000000402037 in default_zoo_watcher ()
      #4 0x000000000040d664 in deliverWatchers (zh=0x515b60, type=4, state=3, path=0x515100 "/mytest", list=0x5177d8) at src/zk_hashtable.c:274
      #5 0x0000000000403861 in process_completions (zh=0x515b60) at src/zookeeper.c:1631
      #6 0x000000000040e1b5 in do_completion (v=Variable "v" is not available.) at src/mt_adaptor.c:333
      #7 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0
      #8 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6
      #9 0x0000000000000000 in ?? ()

      here, a deadlock presents.

      1. ZOOKEEPER-591_2.patch
        0.4 kB
        Mahadev konar
      2. ZOOKEEPER-591_1.patch
        4 kB
        Mahadev konar
      3. ZOOKEEPER-591_1.patch
        4 kB
        Mahadev konar
      4. ZOOKEEPER-591_1.patch
        4 kB
        Mahadev konar
      5. ZOOKEEPER-591.patch
        4 kB
        Mahadev konar
      6. ZOOKEEPER-591.patch
        3 kB
        Mahadev konar
      7. zootest.c
        1 kB
        Mahadev konar
      8. ZOOKEEPER-591.patch
        2 kB
        Mahadev konar
      9. ZOOKEEPER-591.patch
        0.5 kB
        Mahadev konar

        Activity

        Patrick Hunt made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Patrick Hunt made changes -
        Status Patch Available [ 10002 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Mahadev konar made changes -
        Status Reopened [ 4 ] Patch Available [ 10002 ]
        Mahadev konar made changes -
        Attachment ZOOKEEPER-591_2.patch [ 12439082 ]
        Patrick Hunt made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Mahadev konar made changes -
        Status Patch Available [ 10002 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Mahadev konar made changes -
        Attachment ZOOKEEPER-591_1.patch [ 12439006 ]
        Mahadev konar made changes -
        Attachment ZOOKEEPER-591_1.patch [ 12439005 ]
        Mahadev konar made changes -
        Status Open [ 1 ] Patch Available [ 10002 ]
        Mahadev konar made changes -
        Attachment ZOOKEEPER-591_1.patch [ 12438988 ]
        Mahadev konar made changes -
        Status Patch Available [ 10002 ] Open [ 1 ]
        Benjamin Reed made changes -
        Hadoop Flags [Reviewed]
        Mahadev konar made changes -
        Status Open [ 1 ] Patch Available [ 10002 ]
        Mahadev konar made changes -
        Attachment ZOOKEEPER-591.patch [ 12438547 ]
        Mahadev konar made changes -
        Status Patch Available [ 10002 ] Open [ 1 ]
        Mahadev konar made changes -
        Status Open [ 1 ] Patch Available [ 10002 ]
        Mahadev konar made changes -
        Status Patch Available [ 10002 ] Open [ 1 ]
        Mahadev konar made changes -
        Status Open [ 1 ] Patch Available [ 10002 ]
        Mahadev konar made changes -
        Attachment ZOOKEEPER-591.patch [ 12438540 ]
        Mahadev konar made changes -
        Attachment zootest.c [ 12438528 ]
        Patrick Hunt made changes -
        Status Patch Available [ 10002 ] Open [ 1 ]
        Mahadev konar made changes -
        Status Open [ 1 ] Patch Available [ 10002 ]
        Mahadev konar made changes -
        Attachment ZOOKEEPER-591.patch [ 12438438 ]
        Mahadev konar made changes -
        Status Patch Available [ 10002 ] Open [ 1 ]
        Mahadev konar made changes -
        Priority Critical [ 2 ] Blocker [ 1 ]
        Mahadev konar made changes -
        Status Open [ 1 ] Patch Available [ 10002 ]
        Mahadev konar made changes -
        Attachment ZOOKEEPER-591.patch [ 12438345 ]
        Mahadev konar made changes -
        Assignee Benjamin Reed [ breed ] Mahadev konar [ mahadev ]
        Patrick Hunt made changes -
        Assignee Benjamin Reed [ breed ]
        Patrick Hunt made changes -
        Field Original Value New Value
        Fix Version/s 3.3.0 [ 12313976 ]
        Priority Major [ 3 ] Critical [ 2 ]
        Qian Ye created issue -

          People

          • Assignee:
            Mahadev konar
            Reporter:
            Qian Ye
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development