[
https://issues.apache.org/jira/browse/ZOOKEEPER-3868?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17139979#comment-17139979
]
Tudor Bosman commented on ZOOKEEPER-3868:
-----------------------------------------
I tested this in 3.5.8, but the code is the same in 3.6 and trunk, so I imagine
the bug exists there too.
> Completion leak in zookeeper_close
> ----------------------------------
>
> Key: ZOOKEEPER-3868
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-3868
> Project: ZooKeeper
> Issue Type: Bug
> Components: c client
> Affects Versions: 3.7.0, 3.6.1, 3.5.8
> Reporter: Tudor Bosman
> Priority: Major
> Time Spent: 10m
> Remaining Estimate: 0h
>
> 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.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)