bonifaido / rust-zookeeper

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

ZooKeeper::connect doesn't crash if it can not connect #64

Open Jasperav opened 4 years ago

Jasperav commented 4 years ago

I don't have any ZooKeeper server running, but ZooKeeper::connect will not throw an error. My expectation is that if it can not connect, it notifies me. Furthermore, take this code:

use zookeeper::{ZooKeeper, Watcher, WatchedEvent};
use std::time::Duration;

struct LoggingWatcher;
impl Watcher for LoggingWatcher {
    fn handle(&self, e: WatchedEvent) {
        println!("{:?}", e)
    }
}

fn main() {
    // Some url where zookeeper isn't running
    let url = "129.0.0.1:2182";
    let zk = ZooKeeper::connect(url, Duration::from_secs(1), LoggingWatcher).unwrap();

    zk.add_listener(|s| println!("New state is {:?}", s));

    let x = zk.exists("/test", false).unwrap();

    println!("Connected!");
}

zk.exists takes a lot longer than the specified 1 second in the connect method. It takes like a half a minute minute to fail