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

Add a pool idle timeout for subgraph HTTP connectors #3470

Merged
merged 5 commits into from
Jul 20, 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
7 changes: 7 additions & 0 deletions .changesets/maint_garypen_3435_reuse_hyper_pool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Add a pool idle timeout for subgraph HTTP connectors ([Issue #3435](https://github.com/apollographql/router/issues/3435))

Having a high idle pool timeout duration can sometimes trigger situations in which an HTTP request cannot complete (see [this comment](https://github.com/hyperium/hyper/issues/2136#issuecomment-589488526) for more information).

This changeset sets a default timeout duration of 5 seconds, which we may make configurable eventually.

By [@garypen](https://github.com/garypen) in https://github.com/apollographql/router/pull/3470
7 changes: 6 additions & 1 deletion apollo-router/src/services/subgraph_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::Relaxed;
use std::sync::Arc;
use std::task::Poll;
use std::time::Duration;

use ::serde::Deserialize;
use async_compression::tokio::write::BrotliEncoder;
Expand Down Expand Up @@ -86,6 +87,7 @@ const HASH_VERSION_KEY: &str = "version";
const HASH_VERSION_VALUE: i32 = 1;
const HASH_KEY: &str = "sha256Hash";
const GRAPHQL_RESPONSE: mediatype::Name = mediatype::Name::new_unchecked("graphql-response");
const POOL_IDLE_TIMEOUT_DURATION: Option<Duration> = Some(Duration::from_secs(5));
bnjjj marked this conversation as resolved.
Show resolved Hide resolved

// interior mutability is not a concern here, the value is never modified
#[allow(clippy::declare_interior_mutable_const)]
Expand Down Expand Up @@ -181,10 +183,13 @@ impl SubgraphService {
builder.wrap_connector(http_connector)
};

let http_client = hyper::Client::builder()
.pool_idle_timeout(POOL_IDLE_TIMEOUT_DURATION)
.build(connector);
Self {
client: ServiceBuilder::new()
.layer(DecompressionLayer::new())
.service(hyper::Client::builder().build(connector)),
.service(http_client),
service: Arc::new(service.into()),
apq: Arc::new(<AtomicBool>::new(enable_apq)),
subscription_config,
Expand Down