Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deadlock when stop keepalive bg task #941

Merged
merged 1 commit into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions cluster/src/shard_lock_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,13 @@ impl ShardLock {

// Wait for the lease check worker to stop.
if let Some(handle) = self.lease_check_handle.take() {
if let Err(e) = handle.await {
warn!("Failed to wait for the lease check worker to stop, maybe it has exited so ignore it, shard_id:{}, err:{e}", self.shard_id);
}
handle.abort();
}

info!(
"Finish exiting from background keepalive task, shard_id:{}",
self.shard_id
);
}

async fn acquire_lock_with_lease(&self, lease_id: i64, etcd_client: &mut Client) -> Result<()> {
Expand Down Expand Up @@ -711,7 +714,7 @@ impl ShardLockManager {

let mut shard_locks = self.shard_locks.write().await;
let shard_lock = shard_locks.remove(&shard_id);
match shard_lock {
let res = match shard_lock {
Some(mut v) => {
let mut etcd_client = self.etcd_client.clone();
v.revoke(&mut etcd_client).await?;
Expand All @@ -723,7 +726,10 @@ impl ShardLockManager {
warn!("The lock is not exist, shard_id:{shard_id}");
Ok(false)
}
}
};

info!("Finish revoke lock for shard, shard_id:{shard_id}");
res
}
}

Expand Down
6 changes: 6 additions & 0 deletions common_util/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ pin_project! {
}
}

impl<T> JoinHandle<T> {
pub fn abort(&self) {
self.inner.abort();
}
}

impl<T> Future for JoinHandle<T> {
type Output = Result<T>;

Expand Down