Do not reuse a http.Request after a failure in callWithRetry

Closes: #33412

Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
This commit is contained in:
Felix Abecassis 2017-05-26 18:02:31 -07:00
parent e925820bfd
commit 62871ef2fa
2 changed files with 26 additions and 5 deletions

View file

@ -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 {

View file

@ -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()