Skip to content

Commit

Permalink
Merge pull request #390 from fussybeaver/ND/test-race
Browse files Browse the repository at this point in the history
Disable pool to tackle race condition in Hyper 1
  • Loading branch information
fussybeaver authored Mar 23, 2024
2 parents 41f75f6 + feadb6e commit b8217c8
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- run: docker run -ti -e DOCKER_CERT_PATH=/certs -e DOCKER_HOST='tcp://test.example.com:2376' --volumes-from certs --rm --link test-docker-daemon:docker bollard cargo test --features test_ssl,webpki -- --test test_version_ssl
- run: docker run -ti -e DOCKER_CERT_PATH=/certs -e DOCKER_HOST='tcp://test.example.com:2376' -e DOCKER_TLS_VERIFY=1 --volumes-from certs --rm --link test-docker-daemon:docker bollard cargo test --features webpki -- --test test_connect_with_defaults
- run: docker run -ti -e DOCKER_CERT_PATH=/certs -e DOCKER_HOST='https://test.example.com:2376' --volumes-from certs --rm --link test-docker-daemon:docker bollard cargo test --features webpki -- --test test_connect_with_defaults
- run: docker run -ti -e DOCKER_CERT_PATH=/certs -e DOCKER_HOST='https://test.example.com:2376' --volumes-from certs --rm --link test-docker-daemon:docker bollard cargo test --features test_ssl,webpki test_runtime
test_http:
docker:
- image: docker:25.0.3
Expand All @@ -25,6 +26,7 @@ jobs:
- run: docker build -t bollard .
- run: docker run -ti -e DOCKER_HOST='tcp://test.example.com:2375' --rm --link test-docker-daemon:docker bollard cargo test --features test_http -- --test test_version_http
- run: docker run -ti -e DOCKER_HOST='tcp://test.example.com:2375' --rm --link test-docker-daemon:docker bollard cargo test -- --test test_connect_with_defaults
- run: docker run -ti -e DOCKER_HOST='tcp://test.example.com:2375' --rm --link test-docker-daemon:docker bollard cargo test --features test_http test_runtime
test_unix:
docker:
- image: docker:25.0.3
Expand All @@ -34,6 +36,7 @@ jobs:
- run: docker build -t bollard .
- run: resources/dockerfiles/bin/run_integration_tests.sh --tests
- run: docker run -ti -e DOCKER_HOST='unix:///var/run/docker.sock' -v /var/run/docker.sock:/var/run/docker.sock --rm bollard cargo test -- --test test_connect_with_defaults
- run: docker run -ti -e DOCKER_HOST='unix:///var/run/docker.sock' -v /var/run/docker.sock:/var/run/docker.sock --rm bollard cargo test test_runtime
test_buildkit:
docker:
- image: docker:25.0.3
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ hex = "0.4.2"
home = { version = "0.5", optional = true }
http = "1.0"
http-body-util = "0.1.0"
hyper = { version = "1", features = ["client", "http1"] }
hyper = { version = "1.2", features = ["client", "http1"] }
hyper-rustls = { version = "0.26", optional = true }
hyper-util = { version = "0.1.2", features = ["http1", "client-legacy", "tokio"] }
hyper-util = { version = "0.1.3", features = ["http1", "client-legacy", "tokio"] }
log = "0.4"
pin-project-lite = "0.2.8"
num = { version = "0.4", optional = true }
Expand Down Expand Up @@ -78,6 +78,7 @@ flate2 = "1.0"
tar = "0.4"
tokio = { version = "1.7", features = ["fs", "rt-multi-thread", "macros"] }
yup-hyper-mock = { version = "8.0.0" }
once_cell = "1.19.0"

[target.'cfg(unix)'.dependencies]
hyperlocal-next = { version = "0.9.0" }
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ test_script:
- cargo test --verbose --tests -- --nocapture --test-threads 1
- ps: Set-Item -path env:DOCKER_HOST -value npipe:////./pipe/docker_engine
- cargo test --verbose --tests -- --nocapture --test-threads 1 --test test_connect_with_defaults
- cargo test --verbose test_runtime
14 changes: 10 additions & 4 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ impl Docker {
/// - The certificate directory is sourced from the `DOCKER_CERT_PATH` environment variable.
/// - Certificates are named `key.pem`, `cert.pem` and `ca.pem` to indicate the private key,
/// the server certificate and the certificate chain respectively.
/// - The number of threads used for the HTTP connection pool defaults to 1.
/// - The request timeout defaults to 2 minutes.
///
/// # Examples
Expand Down Expand Up @@ -488,7 +487,9 @@ impl Docker {
let https_connector: HttpsConnector<HttpConnector> =
HttpsConnector::from((http_connector, config));

let client_builder = Client::builder(TokioExecutor::new());
let mut client_builder = Client::builder(TokioExecutor::new());
client_builder.pool_max_idle_per_host(0);

let client = client_builder.build(https_connector);
let transport = Transport::Https { client };
let docker = Docker {
Expand Down Expand Up @@ -564,7 +565,9 @@ impl Docker {

let http_connector = HttpConnector::new();

let client_builder = Client::builder(TokioExecutor::new());
let mut client_builder = Client::builder(TokioExecutor::new());
client_builder.pool_max_idle_per_host(0);

let client = client_builder.build(http_connector);
let transport = Transport::Http { client };
let docker = Docker {
Expand Down Expand Up @@ -742,7 +745,8 @@ impl Docker {

let unix_connector = UnixConnector;

let client_builder = Client::builder(TokioExecutor::new());
let mut client_builder = Client::builder(TokioExecutor::new());
client_builder.pool_max_idle_per_host(0);

let client = client_builder.build(unix_connector);
let transport = Transport::Unix { client };
Expand Down Expand Up @@ -819,6 +823,8 @@ impl Docker {

let mut client_builder = Client::builder(TokioExecutor::new());
client_builder.http1_title_case_headers(true);
client_builder.pool_max_idle_per_host(0);

let client = client_builder.build(named_pipe_connector);
let transport = Transport::NamedPipe { client };
let docker = Docker {
Expand Down
56 changes: 56 additions & 0 deletions tests/race_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use bollard::{image::ListImagesOptions, Docker};
use once_cell::sync::OnceCell;

static DOCKER: OnceCell<Docker> = OnceCell::new();
#[cfg(all(unix, not(feature = "test_http"), not(feature = "test_ssl")))]
fn get_docker() -> Result<&'static Docker, bollard::errors::Error> {
DOCKER.get_or_try_init(Docker::connect_with_unix_defaults)
}

#[cfg(feature = "test_http")]
fn get_docker() -> Result<&'static Docker, bollard::errors::Error> {
DOCKER.get_or_try_init(Docker::connect_with_http_defaults)
}

#[cfg(feature = "test_ssl")]
fn get_docker() -> Result<&'static Docker, bollard::errors::Error> {
DOCKER.get_or_try_init(Docker::connect_with_ssl_defaults)
}

#[cfg(windows)]
fn get_docker() -> Result<&'static Docker, bollard::errors::Error> {
DOCKER.get_or_try_init(Docker::connect_with_named_pipe_defaults)
}

#[tokio::test(flavor = "multi_thread")]
async fn test_runtime() {
run_test(10).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_runtime_2() {
run_test(10).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_runtime_3() {
run_test(100).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_runtime_4() {
run_test(100).await;
}

async fn run_test(count: usize) {
let docker = get_docker().unwrap();
for _ in 0..count {
let _ = &docker
.list_images(Some(ListImagesOptions::<String> {
all: true,
..Default::default()
}))
.await
.unwrap();
}
}

0 comments on commit b8217c8

Please sign in to comment.