mirror of
https://github.com/docker/cli.git
synced 2026-01-13 18:22:35 +03:00
Do not reuse a http.Request after a failure in callWithRetry
Closes: #33412 Signed-off-by: Felix Abecassis <fabecassis@nvidia.com> Upstream-commit: 62871ef2fa52b0a2e426c30f36d35a9ba1e92fac Component: engine
This commit is contained in:
@@ -129,15 +129,15 @@ func (c *Client) SendFile(serviceMethod string, data io.Reader, ret interface{})
|
||||
}
|
||||
|
||||
func (c *Client) callWithRetry(serviceMethod string, data io.Reader, retry bool) (io.ReadCloser, error) {
|
||||
req, err := c.requestFactory.NewRequest(serviceMethod, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var retries int
|
||||
start := time.Now()
|
||||
|
||||
for {
|
||||
req, err := c.requestFactory.NewRequest(serviceMethod, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
if !retry {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -38,6 +39,26 @@ func TestFailedConnection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailOnce(t *testing.T) {
|
||||
addr := setupRemotePluginServer()
|
||||
defer teardownRemotePluginServer()
|
||||
|
||||
failed := false
|
||||
mux.HandleFunc("/Test.FailOnce", func(w http.ResponseWriter, r *http.Request) {
|
||||
if !failed {
|
||||
failed = true
|
||||
panic("Plugin not ready")
|
||||
}
|
||||
})
|
||||
|
||||
c, _ := NewClient(addr, &tlsconfig.Options{InsecureSkipVerify: true})
|
||||
b := strings.NewReader("body")
|
||||
_, err := c.callWithRetry("Test.FailOnce", b, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEchoInputOutput(t *testing.T) {
|
||||
addr := setupRemotePluginServer()
|
||||
defer teardownRemotePluginServer()
|
||||
|
||||
Reference in New Issue
Block a user