diff --git a/pom.xml b/pom.xml
index ebfe7dc7b0..609fb6efd0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -94,7 +94,7 @@
com.squareup.okhttp
okhttp-urlconnection
- 2.0.0
+ 2.2.0
true
diff --git a/src/main/java/org/kohsuke/github/GHRateLimit.java b/src/main/java/org/kohsuke/github/GHRateLimit.java
index 9d54953d54..301bd7993d 100644
--- a/src/main/java/org/kohsuke/github/GHRateLimit.java
+++ b/src/main/java/org/kohsuke/github/GHRateLimit.java
@@ -1,5 +1,7 @@
package org.kohsuke.github;
+import java.util.Date;
+
/**
* Rate limit.
* @author Kohsuke Kawaguchi
@@ -10,12 +12,28 @@ public class GHRateLimit {
*/
public int remaining;
/**
- * Alotted API call per hour.
+ * Allotted API call per hour.
*/
public int limit;
+ /**
+ * The time at which the current rate limit window resets in UTC epoch seconds.
+ */
+ public Date reset;
+
+ /**
+ * Non-epoch date
+ */
+ public Date getResetDate() {
+ return new Date(reset.getTime() * 1000);
+ }
+
@Override
public String toString() {
- return remaining+"/"+limit;
+ return "GHRateLimit{" +
+ "remaining=" + remaining +
+ ", limit=" + limit +
+ ", resetDate=" + getResetDate() +
+ '}';
}
}
diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java
index e2b0362a4c..a5571e5139 100644
--- a/src/main/java/org/kohsuke/github/Requester.java
+++ b/src/main/java/org/kohsuke/github/Requester.java
@@ -421,15 +421,18 @@ private InputStream wrapStream(HttpURLConnection uc, InputStream in) throws IOEx
* Otherwise throw an exception reporting an error.
*/
/*package*/ void handleApiError(IOException e, HttpURLConnection uc) throws IOException {
- if ("0".equals(uc.getHeaderField("X-RateLimit-Remaining"))) {
- // API limit reached. wait 10 secs and return normally
- try {
- Thread.sleep(10000);
- return;
- } catch (InterruptedException _) {
- throw (InterruptedIOException)new InterruptedIOException().initCause(e);
- }
- }
+ // Disable this check, because it causes "infinite" thread usage when:
+ // 1) set bad password you can't apply changed without interrupting thread
+ // 2) exhausted limit will cause lock upto 1h until reset time
+// if ("0".equals(uc.getHeaderField("X-RateLimit-Remaining"))) {
+// // API limit reached. wait 10 secs and return normally
+// try {
+// Thread.sleep(10000);
+// return;
+// } catch (InterruptedException _) {
+// throw (InterruptedIOException)new InterruptedIOException().initCause(e);
+// }
+// }
if (e instanceof FileNotFoundException)
throw e; // pass through 404 Not Found to allow the caller to handle it intelligently