aerospike / aerospike-client-rust

Rust client for the Aerospike database
https://www.aerospike.com/
Other
82 stars 29 forks source link

Client.is_connected() returns true even after client.close() is called #86

Closed abhilashg1 closed 4 years ago

abhilashg1 commented 4 years ago

hi

am trying with a simple code to check the basics of Rust client, but the client.close() is not working.

#[macro_use]
extern crate aerospike;

use std::env;
use std::sync::Arc;
use std::time::Instant;
use std::thread;

use aerospike::Client;
use aerospike::{Bins, ClientPolicy, ReadPolicy, WritePolicy};
use aerospike::operations;

fn main() {
    let mut cpolicy = ClientPolicy::default();
    let user = env::var("AEROSPIKE_USER")
        .unwrap_or(String::from("admin"));
    let password = env::var("AEROSPIKE_PASSWORD")
        .unwrap_or(String::from("admin"));
    cpolicy.set_user_password(user, password).unwrap();
    let hosts = env::var("AEROSPIKE_HOSTS")
        .unwrap_or(String::from("127.0.0.1:3000"));
    let client = Client::new(&cpolicy, &hosts)
        .expect("Failed to connect to cluster");
    let client = Arc::new(client);

    let now = Instant::now();

    let rpolicy = ReadPolicy::default();
    let wpolicy = WritePolicy::default();
    let key = as_key!("tempspace", "test", "test");

    let bins = [
        as_bin!("int", 999),
        as_bin!("str", "Hello, World!"),
    ];
    client.put(&wpolicy, &key, &bins).unwrap();
    let rec = client.get(&rpolicy, &key, Bins::All);
    println!("Record: {}", rec.unwrap());

    client.touch(&wpolicy, &key).unwrap();
    let rec = client.get(&rpolicy, &key, Bins::All);
    println!("Record: {}", rec.unwrap());

    let rec = client.get(&rpolicy, &key, Bins::None);
    println!("Record Header: {}", rec.unwrap());

    let exists = client.exists(&wpolicy, &key).unwrap();
    println!("exists: {}", exists);

    let bin = as_bin!("int", "123");
    let ops = &vec![operations::put(&bin), operations::get()];
    let op_rec = client.operate(&wpolicy, &key, ops);
    println!("operate: {}", op_rec.unwrap());

    let existed = client.delete(&wpolicy, &key).unwrap();
    println!("existed (should be true): {}", existed);

    let existed = client.delete(&wpolicy, &key).unwrap();
    println!("existed (should be false): {}", existed);

    client.close().expect("unable to close the connection");

    if client.is_connected() {
        println!("After close call-connected to AS servers");
    } else {
        println!("After close call-not connected");
    }

    println!("total time: {:?}", now.elapsed());

}

output observed is:

    Finished dev [unoptimized + debuginfo] target(s) in 1.14s
     Running `target/debug/hello-world`
Record: key: None, bins: {int: 999, str: Hello, World!}, generation: 1, ttl: none
Record: key: None, bins: {str: Hello, World!, int: 999}, generation: 2, ttl: none
Record Header: key: None, bins: {}, generation: 2, ttl: none
exists: true
operate: key: None, bins: {int: 123, str: Hello, World!}, generation: 3, ttl: none
existed (should be true): true
existed (should be false): false
After close call-connected to AS servers
total time: 2.902384ms
jhecking commented 4 years ago

Thanks for reporting this bug! client.close() does close the connection to the server and frees resources as expected, but it does not update the client's internal state to mark the connection as closed, so client.is_connected() continues to return true, even after client.close() was called successfully.