Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
3.7.0, 3.6.1, 3.5.8
-
None
-
None
Description
Using the multithreaded C library.
Due to a race condition between `zookeeper_close` and `do_completion`, it is possible for `zookeeper_close` to close the handle without running the pending completions, causing a completion leak (not calling the client's completion callbacks) and a memory leak.
`zookeeper_close` sets `close_requested` here: https://github.com/apache/zookeeper/blob/master/zookeeper-client/zookeeper-client-c/src/zookeeper.c#L3752; after that point, the completion thread can exit at any time: https://github.com/apache/zookeeper/blob/8da9c723ac1a889c989ecefada722ed858049537/zookeeper-client/zookeeper-client-c/src/mt_adaptor.c#L473
But, even after `zookeeper_close`, completions can still be added to `completions_to_process` from two different places: the IO thread (which is still running) and `zookeeper_close` itself, via `free_completions`: https://github.com/apache/zookeeper/blob/master/zookeeper-client/zookeeper-client-c/src/zookeeper.c#L3760
I have a fix (I'll update this issue with the pull request) that uses a separate `terminate_completion` flag in `adaptor_threads` instead of `zh->close_requested` to make the IO thread exit.