-
Notifications
You must be signed in to change notification settings - Fork 736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not assume server time is in sync with local machine time on rate limit path #1972
Do not assume server time is in sync with local machine time on rate limit path #1972
Conversation
0fd8887
to
2973e57
Compare
2973e57
to
50b967e
Compare
long parseWaitTime(GitHubConnectorResponse connectorResponse) { | ||
String v = connectorResponse.header("X-RateLimit-Reset"); | ||
if (v == null) | ||
return Duration.ofMinutes(1).toMillis(); // can't tell, return 1 min | ||
|
||
return Math.max(1000, Long.parseLong(v) * 1000 - System.currentTimeMillis()); | ||
// Don't use ZonedDateTime.now(), because the local and remote server times may not be in sync | ||
// Instead, we can take advantage of the Date field in the response to see what time the remote server | ||
// thinks it is | ||
String dateField = connectorResponse.header("Date"); | ||
ZonedDateTime now; | ||
if (dateField != null) { | ||
now = ZonedDateTime.parse(dateField, DateTimeFormatter.RFC_1123_DATE_TIME); | ||
} else { | ||
now = ZonedDateTime.now(); | ||
} | ||
}; | ||
return Math.max(MINIMUM_RATE_LIMIT_RETRY_MILLIS, (Long.parseLong(v) - now.toInstant().getEpochSecond()) * 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now mostly the same as the abuse limit wait parse code you submitted. Would it make sense to extract this into a shared method? Perhaps even make it public so others could use it? Opened #1973 to track this.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1972 +/- ##
=========================================
Coverage 83.09% 83.10%
- Complexity 2329 2331 +2
=========================================
Files 231 231
Lines 7168 7172 +4
Branches 377 378 +1
=========================================
+ Hits 5956 5960 +4
Misses 974 974
Partials 238 238 ☔ View full report in Codecov by Sentry. |
See discussion in #1909 and companion PR in #1971. On this test, I did try and cover the guard for missing dates with tests.
Description
Before submitting a PR:
@link
JavaDoc entries to the relevant documentation on https://docs.github.com/en/rest .mvn -D enable-ci clean install site
locally. If this command doesn't succeed, your change will not pass CI.main
. You will create your PR from that branch.When creating a PR: