The correct step about close client is the client send CLOSE_OP to the server, wait for several seconds, the server will process the terminal request and close the fd.
But the zookeeper_close interface is wrong, because the adaptor_send_queue(zh, 3000) (line 2332), will first wait the timeout then send the request.
The right order is first send the request then wait the timeout. I change as follow:
$svn diff src/c/src/zookeeper.c
— src/c/src/zookeeper.c (revision 1140451)
+++ src/c/src/zookeeper.c (working copy)
@@ -2329,7 +2329,8 @@
/* make sure the close request is sent; we set timeout to an arbitrary
- (but reasonable) number of milliseconds since we want the call to block*/
- rc=adaptor_send_queue(zh, 3000);
+ rc=adaptor_send_queue(zh, 0);
LOG_INFO(("Freeing zookeeper resources for sessionId=%#llx\n",