sdk-go icon indicating copy to clipboard operation
sdk-go copied to clipboard

Retries don't work for HTTP POST resquests with a body

Open aruiz14 opened this issue 3 years ago • 2 comments
trafficstars

I'm using Tekton and I believe I've found a bug in this library, since it's used for sending CloudEvents based on Kubernetes events. By default, it uses the ExponentialBackoff retry strategy.

I modeled the sink to respond with a retriable HTTP status code, e.g. 425 Too Early, but I only observe 1 attempt. By inspecting the controller logs, I eventually see the give-up error message after 10 retries, which is something like:

Cloud Event Failure' Post ... : http: ContentLength=4137 with Body length 0 (10x)

I believe the reason for this is that the retry logic reuses the same http.Request object to perform multiple calls. The Body of the request is a io.ReaderCloser interface, but it's not "rewinded"/reset before trying to read again from it, so it ends up returning EOF. This is a known limitation of the standard library and there are libraries like https://github.com/hashicorp/go-retryablehttp that provide a solution for this exact problem.

aruiz14 avatar Jan 10 '22 13:01 aruiz14

oh interesting. Thanks for the report!

n3wscott avatar Jan 18 '22 19:01 n3wscott

Fixed in #774

embano1 avatar Oct 02 '22 13:10 embano1