From a296b00059aed51b19b02263bf3013399faee276 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 1 Mar 2012 18:05:40 -0800 Subject: [PATCH] [SECURITY-24] Exponential back-off of retry. If we fail to obtain the update center metadata, don't keep retrying every 15 seconds, but use exponential time out to avoid overloading our server in case of a problem. --- changelog.html | 2 ++ .../src/main/java/hudson/model/UpdateSite.java | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/changelog.html b/changelog.html index 52f7a2ab31..6728735af0 100644 --- a/changelog.html +++ b/changelog.html @@ -59,6 +59,8 @@ Upcoming changes Fixed NPE in Groovy script execution via CLI (issue 12302)
  • Fixed bug where a queued build could start while the previous build was still in its post production state. +
  • + Improved the error retry logic of update center retrieval.
  • Supported programmatic retrieval/update of slave config.xml
  • diff --git a/core/src/main/java/hudson/model/UpdateSite.java b/core/src/main/java/hudson/model/UpdateSite.java index 74bccfb147..fbfa5db9d9 100644 --- a/core/src/main/java/hudson/model/UpdateSite.java +++ b/core/src/main/java/hudson/model/UpdateSite.java @@ -35,6 +35,7 @@ import hudson.util.FormValidation.Kind; import hudson.util.HttpResponses; import hudson.util.IOUtils; import hudson.util.TextFile; +import hudson.util.TimeUnit2; import hudson.util.VersionNumber; import jenkins.model.Jenkins; import net.sf.json.JSONException; @@ -107,6 +108,12 @@ public class UpdateSite { */ private transient volatile long lastAttempt = -1; + /** + * If the attempt to fetch data fails, we progressively use longer time out before retrying, + * to avoid overloading the server. + */ + private transient volatile long retryWindow; + /** * ID string for this update source. */ @@ -162,6 +169,7 @@ public class UpdateSite { } LOGGER.info("Obtained the latest update center data file for UpdateSource " + id); + retryWindow = 0; getDataFile().write(json); return FormValidation.ok(); } @@ -278,8 +286,14 @@ public class UpdateSite { if(dataTimestamp==-1) dataTimestamp = getDataFile().file.lastModified(); long now = System.currentTimeMillis(); - boolean due = now - dataTimestamp > DAY && now - lastAttempt > 15000; - if(due) lastAttempt = now; + + retryWindow = Math.max(retryWindow,SECONDS.toMillis(15)); + + boolean due = now - dataTimestamp > DAY && now - lastAttempt > retryWindow; + if(due) { + lastAttempt = now; + retryWindow = Math.min(retryWindow*2, HOURS.toMillis(1)); // exponential back off but at most 1 hour + } return due; }