Created
August 31, 2015 05:16
-
-
Save mountkin/f2486223473965c440e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Must start docker daemon with -H tcp://127.0.0.1:2375 | |
package main | |
import ( | |
"fmt" | |
"io" | |
"net/http" | |
"os" | |
"os/exec" | |
"strings" | |
"sync" | |
"time" | |
) | |
type nopWriter struct{} | |
func (nopWriter) Write(p []byte) (n int, err error) { return len(p), nil } | |
func main() { | |
var wg sync.WaitGroup | |
for i := 0; i < 10; i++ { | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
// If the "-i" is not specified or comment out the stats API call the problem won't reproduce. | |
for { | |
id := Exec("run", "-i", "-t", "-d", "busybox", "sh", "-c", "sleep 2") | |
req, _ := http.NewRequest("GET", "http://127.0.0.1:2375/containers/"+id+"/stats", nil) | |
resp, err := http.DefaultClient.Do(req) | |
if err != nil { | |
fmt.Println(err, resp) | |
break | |
} | |
go io.Copy(nopWriter{}, resp.Body) | |
time.Sleep(2500 * time.Millisecond) | |
resp.Body.Close() | |
Exec("rm", "-f", id) | |
} | |
}() | |
} | |
wg.Wait() | |
} | |
func Exec(args ...string) string { | |
out, err := exec.Command("docker", args...).CombinedOutput() | |
if err != nil { | |
fmt.Println(err) | |
fmt.Println(string(out)) | |
os.Exit(1) | |
} | |
return strings.TrimSpace(string(out)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment