From 28137c4c149385bce5157413c54f60a460a19c5a Mon Sep 17 00:00:00 2001 From: DaneEveritt Date: Sat, 9 Jul 2022 15:42:29 -0400 Subject: [PATCH] Copy the body buffer otherwise subsequent backoff attempts will not have a buffer to send --- remote/http.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/remote/http.go b/remote/http.go index 872aa78..8f44bd6 100644 --- a/remote/http.go +++ b/remote/http.go @@ -129,10 +129,16 @@ func (c *client) requestOnce(ctx context.Context, method, path string, body io.R // and adds the required authentication headers to the request that is being // created. Errors returned will be of the RequestError type if there was some // type of response from the API that can be parsed. -func (c *client) request(ctx context.Context, method, path string, body io.Reader, opts ...func(r *http.Request)) (*Response, error) { +func (c *client) request(ctx context.Context, method, path string, body *bytes.Buffer, opts ...func(r *http.Request)) (*Response, error) { var res *Response err := backoff.Retry(func() error { - r, err := c.requestOnce(ctx, method, path, body, opts...) + var b bytes.Buffer + if body != nil { + if _, err := b.Write(body.Bytes()); err != nil { + return backoff.Permanent(errors.Wrap(err, "http: failed to copy body buffer")) + } + } + r, err := c.requestOnce(ctx, method, path, &b, opts...) if err != nil { if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { return backoff.Permanent(err)