Skip to content

Commit 453b1cb

Browse files
authored
lease keep alive return lease not found error (#87)
1 parent f9110df commit 453b1cb

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tls-roots = ["tls", "tonic/tls-roots"]
1919
pub-response-field = ["visible"]
2020

2121
[dependencies]
22-
tonic = "0.12"
22+
tonic = "0.12.3"
2323
prost = "0.13"
2424
tokio = "1.38"
2525
tokio-stream = "0.1"
@@ -36,7 +36,7 @@ hyper-util = { version = "0.1", features = ["client-legacy"], optional = true }
3636
tokio = { version = "1.38", features = ["full"] }
3737

3838
[build-dependencies]
39-
tonic-build = { version = "0.12", default-features = false, features = ["prost"] }
39+
tonic-build = { version = "0.12.3", default-features = false, features = ["prost"] }
4040

4141
[package.metadata.docs.rs]
4242
features = ["tls", "tls-roots"]

build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn main() {
44

55
tonic_build::configure()
66
.build_server(false)
7-
.compile(
7+
.compile_protos(
88
&[
99
"proto/auth.proto",
1010
"proto/kv.proto",

examples/lease.rs

+5
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,10 @@ async fn main() -> Result<(), Error> {
4040
// revoke a lease
4141
let _resp = client.lease_revoke(id).await?;
4242
println!("revoke a lease with id {:?}", id);
43+
44+
// keep alive a revoked lease returns error
45+
if let Err(err) = client.lease_keep_alive(id).await {
46+
println!("revoked lease {:?} keep alive error: {:?}", id, err);
47+
}
4348
Ok(())
4449
}

src/rpc/lease.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ impl LeaseClient {
8383
let mut stream = self.inner.lease_keep_alive(receiver).await?.into_inner();
8484

8585
let id = match stream.message().await? {
86-
Some(resp) => resp.id,
86+
Some(resp) => {
87+
if resp.ttl <= 0 {
88+
return Err(Error::LeaseKeepAliveError("lease not found".to_string()));
89+
}
90+
resp.id
91+
}
8792
None => {
8893
return Err(Error::WatchError(
8994
"failed to create lease keeper".to_string(),

tests/client.rs

+3
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ async fn test_keep_alive() -> Result<()> {
294294
assert_eq!(resp.ttl(), 60);
295295

296296
client.lease_revoke(id).await?;
297+
298+
// keep alive a revoked lease should return error
299+
assert!(client.lease_keep_alive(id).await.is_err());
297300
Ok(())
298301
}
299302

0 commit comments

Comments
 (0)