Skip to content

Commit

Permalink
Fix introspection query deduplication (#6257)
Browse files Browse the repository at this point in the history
Introspection queries are not supposed to be cached, but their result still needs to be sent to deduplicated queries. This also fixes a case where errors returned by `poll_ready` were not sent to deduplicated queries
  • Loading branch information
Geal authored Nov 15, 2024
1 parent a22c838 commit d6135f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changesets/fix_geal_introspection_dedup_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Fix introspection query deduplication ([Issue #6249](https://github.com/apollographql/router/issues/6249))

To reduce CPU usage, query planning and introspection queries are deduplicated. In some cases, deduplicated introspection queries were not receiving their result. This makes sure that answers are sent in all cases.

By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/6257
18 changes: 17 additions & 1 deletion apollo-router/src/query_planner/caching_query_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,19 @@ where
// of restarting the query planner until another timeout
tokio::task::spawn(
async move {
let res = self.delegate.ready().await?.call(request).await;
let service = match self.delegate.ready().await {
Ok(service) => service,
Err(error) => {
let e = Arc::new(error);
let err = e.clone();
tokio::spawn(async move {
entry.insert(Err(err)).await;
});
return Err(CacheResolverError::RetrievalError(e));
}
};

let res = service.call(request).await;

match res {
Ok(QueryPlannerResponse { content, errors }) => {
Expand All @@ -536,6 +548,10 @@ where
tokio::spawn(async move {
entry.insert(Ok(content)).await;
});
} else {
tokio::spawn(async move {
entry.send(Ok(content)).await;
});
}
}

Expand Down

0 comments on commit d6135f6

Please sign in to comment.