[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-2320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15345418#comment-15345418
 ] 

Abraham Fine commented on ZOOKEEPER-2320:
-----------------------------------------

[~rgs] 

While working on this issue [~phunt] and I noticed that the behavior of the C 
client exhibits when removing a watch in "local" mode is different than the way 
the java client behaves ([~Hadriel] mentioned this in the description).

Currently, when local mode is set, the C client simply removes the watches 
locally (then makes the {{notify_sync_completion}} call that is causing the 
crash) and does not try to connect to the server. The java client will attempt 
to remove the watches from the server as well but it will always remove the 
watches locally. The java client's behavior is more in line with my 
interpretation of the documentation of the C client and I tried to make the C 
client's behavior match the documentation/java client here.

Now, when the {{local}} flag is set, the C client will remove the watches 
locally (this behavior is always done synchronously) and then it will try to 
remove them from the server.

In addition, the {{zk_hashtable.h}} file has been moved to the {{include}} 
directory so that we can check for local watches in the tests.



> C-client crashes when removing watcher asynchronously in "local" mode
> ---------------------------------------------------------------------
>
>                 Key: ZOOKEEPER-2320
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2320
>             Project: ZooKeeper
>          Issue Type: Bug
>          Components: c client
>    Affects Versions: 3.5.1
>            Reporter: Hadriel Kaplan
>            Assignee: Abraham Fine
>         Attachments: ZOOKEEPER-2320.patch
>
>
> The C-client library will crash when invoking the asynchronous 
> {{zoo_aremove_watchers()}} API function with the '{{local}}' argument set to 
> 1.
> The reason is: if the local argument is 1/true, then the code does 
> '{{notify_sync_completion((struct sync_completion *)data);}}' But casting the 
> '{{data}}' variable to a {{sync_completion}} struct pointer is bogus/invalid, 
> and when it's later handles as that struct pointer it's accessing invalid 
> memory.
> As a side note: it will work ok when called _synchronously_ through 
> {{zoo_remove_watchers()}}, because that function creates a 
> {{sync_completion}} struct and passes it to the asynch 
> {{zoo_aremove_watchers()}}, but it will not work ok when the asynch function 
> is used directly for the reason stated perviously.
> Another side note: the docs state that setting the 'local' flag makes the 
> C-client remove the watcher "even if there is no server connection" - but 
> really it makes the C-client remove the watcher without notifying the server 
> at *all*, even if the connection to a server is up. (well... that's what it 
> would do if it didn't just crash instead ;)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to