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(query): remove unexpected strong ref for http query #13807

Merged
merged 7 commits into from
Nov 27, 2023
22 changes: 18 additions & 4 deletions src/query/service/src/servers/http/v1/query/http_query_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,34 @@ impl HttpQueryManager {

let self_clone = self.clone();
let query_id_clone = query_id.to_string();
let query_clone = query.clone();
let query_result_timeout_secs = query.result_timeout_secs;

// downgrade to weak reference
// it may cannot destroy with final or kill when we hold ref of Arc<HttpQuery>
let http_query_weak = Arc::downgrade(&query);

GlobalIORuntime::instance().spawn(query_id, async move {
loop {
match query_clone.check_expire().await {
let expire_res = match http_query_weak.upgrade() {
None => {
break;
}
Some(query) => query.check_expire().await,
};

match expire_res {
ExpireResult::Expired => {
let msg = format!(
"http query {} timeout after {} s",
&query_id_clone, query_clone.result_timeout_secs
&query_id_clone, query_result_timeout_secs
);
if self_clone.remove_query(&query_id_clone).await.is_none() {
warn!("{msg}, but fail to remove");
} else {
warn!("{msg}");
query.kill(&msg).await;
if let Some(query) = http_query_weak.upgrade() {
query.kill(&msg).await;
}
};
break;
}
Expand Down
Loading