hashicorp / go-retryablehttp

Retryable HTTP client in Go
Mozilla Public License 2.0
1.99k stars 251 forks source link

Add support for milliseconds #115

Closed lululombard closed 3 years ago

lululombard commented 4 years ago

Hello, This package works well except with Discord webhook endpoints.

Their reply looks like this:

{
  "global": false,
  "message": "You are being rate limited.",
  "retry_after": 555
}

The thing is, retry_after is specified in milliseconds, but go-retryablehttp will wait for more than 9 minutes because it handles it as seconds.

I looked at the doc and couldn't find a way to handle milliseconds. Did I miss something or is it a missing feature? Thanks

ryanuber commented 3 years ago

Hey @lululombard ! Thanks for opening this.

Based on the response payload you pasted, I assume that Discord is also returning the Retry-After HTTP header with a value of 555 in your case, correct? If so, per the HTTP spec, the units are seconds (see the RetryAfter header section).

I would perhaps contact Discord to verify. It's possible that in a rate limiting scenario they actually do send you away for a long time. It could also be that they mistakenly made the units milliseconds, in which case this would be a bug on their end.

Either way, I don't think retryablehttp will support anything that goes against the HTTP spec.

Hope that helps! I'm going to close this but please feel free to re-open if you have any further questions.

lululombard commented 3 years ago

Thanks for the reply! I ended up writing my own retry code, but I understand how you feel about this, it's definitely an issue on Discord's end 🙂