Skip to content

Commit bc5cb4b

Browse files
committed
Handle KeyError if rate limit refills between update and status
1 parent a3baf24 commit bc5cb4b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

roundup/rest.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,19 @@ def dispatch(self, method, uri, input):
20752075
# User exceeded limits: tell humans how long to wait
20762076
# Headers above will do the right thing for api
20772077
# aware clients.
2078-
msg = _("Api rate limits exceeded. Please wait: %s seconds.") % limitStatus['Retry-After']
2078+
try:
2079+
retry_after = limitStatus['Retry-After']
2080+
except KeyError:
2081+
# handle race condition. If the time between
2082+
# the call to grca.update and grca.status
2083+
# is sufficient to reload the bucket by 1
2084+
# item, Retry-After will be missing from
2085+
# limitStatus. So report a 1 second delay back
2086+
# to the client. We treat update as sole
2087+
# source of truth for exceeded rate limits.
2088+
retry_after = 1
2089+
2090+
msg = _("Api rate limits exceeded. Please wait: %s seconds.") % retry_after
20792091
output = self.error_obj(429, msg, source="ApiRateLimiter")
20802092
else:
20812093
for header, value in limitStatus.items():

0 commit comments

Comments
 (0)