From 69535f167a1ff1e7c8e0b2c85b0931b3cf12035e Mon Sep 17 00:00:00 2001 From: Dong Chen Date: Thu, 18 Feb 2016 18:02:10 -0800 Subject: [PATCH 1/4] Do not recycle connections. Let net/http handles connections. Signed-off-by: Dong Chen --- api/handlers.go | 2 -- api/utils.go | 1 - 2 files changed, 3 deletions(-) diff --git a/api/handlers.go b/api/handlers.go index 09a9c0bd41..187548efc6 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -477,7 +477,6 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) { // cleanup defer resp.Body.Close() - defer closeIdleConnections(client) data, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -786,7 +785,6 @@ func postContainersExec(c *context, w http.ResponseWriter, r *http.Request) { // cleanup defer resp.Body.Close() - defer closeIdleConnections(client) // check status code if resp.StatusCode < 200 || resp.StatusCode >= 400 { diff --git a/api/utils.go b/api/utils.go index 08bb8b2aab..fd09c5f9b7 100644 --- a/api/utils.go +++ b/api/utils.go @@ -121,7 +121,6 @@ func proxyAsync(engine *cluster.Engine, w http.ResponseWriter, r *http.Request, // cleanup resp.Body.Close() - closeIdleConnections(client) return nil } From e51566d25596b43525d4f64225d53d2f5cb18cd0 Mon Sep 17 00:00:00 2001 From: Dong Chen Date: Fri, 19 Feb 2016 14:45:15 -0800 Subject: [PATCH 2/4] Remove closeIdleConnections function. Signed-off-by: Dong Chen --- api/utils.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/api/utils.go b/api/utils.go index fd09c5f9b7..3eb33d8746 100644 --- a/api/utils.go +++ b/api/utils.go @@ -89,13 +89,6 @@ func copyHeader(dst, src http.Header) { } } -// prevents leak with https -func closeIdleConnections(client *http.Client) { - if tr, ok := client.Transport.(*http.Transport); ok { - tr.CloseIdleConnections() - } -} - func proxyAsync(engine *cluster.Engine, w http.ResponseWriter, r *http.Request, callback func(*http.Response)) error { // RequestURI may not be sent to client r.RequestURI = "" From 06ef4a99e6429ed0688c98a98e4f32d1f7e1fc22 Mon Sep 17 00:00:00 2001 From: Dong Chen Date: Fri, 19 Feb 2016 18:29:49 -0800 Subject: [PATCH 3/4] Test connection count between swarm manager and nodes. Signed-off-by: Dong Chen --- .../nodemanagement/connection.bats | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/integration/nodemanagement/connection.bats diff --git a/test/integration/nodemanagement/connection.bats b/test/integration/nodemanagement/connection.bats new file mode 100644 index 0000000000..4261817461 --- /dev/null +++ b/test/integration/nodemanagement/connection.bats @@ -0,0 +1,41 @@ +#!/usr/bin/env bats + +load ../helpers + +function teardown() { + swarm_manage_cleanup + stop_docker +} + +@test "Swarm not leak tcp connections" { + # Start engine with busybox image + start_docker_with_busybox 2 + # Start swarm and check it can reach the node + swarm_manage --engine-refresh-min-interval "20s" --engine-refresh-max-interval "20s" --engine-failure-retry 20 "${HOSTS[0]},${HOSTS[1]}" + eval "docker_swarm info | grep -q -i 'Nodes: 2'" + + # create busybox with host network so that we can get netstat + run docker_swarm run -itd --name=busybox0 --net=host -e constraint:node==node-0 busybox sh + [ "$status" -eq 0 ] + run docker_swarm run -itd --name=busybox1 --net=host -e constraint:node==node-1 busybox sh + [ "$status" -eq 0 ] + + # run most common container operations + for((i=0; i<30; i++)); do + # test postContainerCreate + docker_swarm run --name="hello$i" hello-world + # test getContainerJSON + docker_swarm inspect "hello$i" + # test proxyContainer + docker_swarm logs "hello$i" + # test proxyContainerAndForceRefresh + docker_swarm stop "hello$i" + done + + # get connection count + count0=$(docker_swarm exec busybox0 netstat -an | grep "${HOSTS[0]}" | grep -i "ESTABLISHED" | wc -l) + count1=$(docker_swarm exec busybox1 netstat -an | grep "${HOSTS[1]}" | grep -i "ESTABLISHED" | wc -l) + [[ "$count0" -le 10 ]] + [[ "$count1" -le 10 ]] +} + From acf09695f74f8d6e7c068a9d5fede3cb4b0b3e51 Mon Sep 17 00:00:00 2001 From: Dong Chen Date: Fri, 19 Feb 2016 22:33:39 -0800 Subject: [PATCH 4/4] Skip one test in Docker 1.9 for runC bug. Signed-off-by: Dong Chen --- test/integration/nodemanagement/nodehealth.bats | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/integration/nodemanagement/nodehealth.bats b/test/integration/nodemanagement/nodehealth.bats index 4e0402164e..6f352f3e34 100644 --- a/test/integration/nodemanagement/nodehealth.bats +++ b/test/integration/nodemanagement/nodehealth.bats @@ -8,6 +8,13 @@ function teardown() { } @test "scheduler avoids failing node" { + # Docker issue #14203 in runC causing this test to fail. + # Issue fixed in Docker 1.10 + run docker --version + if [[ "${output}" == "Docker version 1.9"* ]]; then + skip + fi + # Start 1 engine and register it in the file. start_docker 2 # Start swarm and check it can reach the node