From 0f9d856a4db258346ac41ed40d78bfa84ff89f61 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 13 Nov 2024 14:34:02 +0100 Subject: [PATCH 1/3] Fix introspection query deduplication Introspection queries are not supposed to be cached, but their result still needds to be sent to deduplicated queries --- apollo-router/src/query_planner/caching_query_planner.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apollo-router/src/query_planner/caching_query_planner.rs b/apollo-router/src/query_planner/caching_query_planner.rs index 688ce1c697..33cda8db24 100644 --- a/apollo-router/src/query_planner/caching_query_planner.rs +++ b/apollo-router/src/query_planner/caching_query_planner.rs @@ -560,6 +560,10 @@ where tokio::spawn(async move { entry.insert(Ok(content)).await; }); + } else { + tokio::spawn(async move { + entry.send(Ok(content)).await; + }); } } From db89fccb1634239a34a70cfbcabcc84a049c7645 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 13 Nov 2024 14:41:30 +0100 Subject: [PATCH 2/3] handle readiness errors for deduplicated queries too --- .../src/query_planner/caching_query_planner.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apollo-router/src/query_planner/caching_query_planner.rs b/apollo-router/src/query_planner/caching_query_planner.rs index 33cda8db24..b06a5c957b 100644 --- a/apollo-router/src/query_planner/caching_query_planner.rs +++ b/apollo-router/src/query_planner/caching_query_planner.rs @@ -538,7 +538,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 { From c605324370e0b92172555286cbbc1d37dcb672e2 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 13 Nov 2024 15:09:52 +0100 Subject: [PATCH 3/3] changeset --- .changesets/fix_geal_introspection_dedup_fix.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changesets/fix_geal_introspection_dedup_fix.md diff --git a/.changesets/fix_geal_introspection_dedup_fix.md b/.changesets/fix_geal_introspection_dedup_fix.md new file mode 100644 index 0000000000..f93112b815 --- /dev/null +++ b/.changesets/fix_geal_introspection_dedup_fix.md @@ -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 \ No newline at end of file