bonifaido / rust-zookeeper

Pure Rust library for Apache ZooKeeper built on MIO
MIT License
206 stars 46 forks source link

Avoid leaking watch threads on client shutdown #87

Closed behos closed 2 years ago

behos commented 2 years ago

When creating the ZkWatch struct, we keep a reference to the sender of the channel and clone it on sender() to pass along to the ZkIo struct.

When the ZkIo thread finishes, its copy of the sender is dropped but the channel is not closed because the watch has a reference to its own sender, therefore leaking the thread.

Instead, we can prevent the watch from ever taking the sender by returning it through the constructor, so that it can be owned by ZkIo which will close the channel as expected on shutdown.