diff --git a/router/java/src/net/i2p/router/JobQueue.java b/router/java/src/net/i2p/router/JobQueue.java index 5e92d9d25..136d20ac3 100644 --- a/router/java/src/net/i2p/router/JobQueue.java +++ b/router/java/src/net/i2p/router/JobQueue.java @@ -486,7 +486,24 @@ public class JobQueue { // Hopefully nobody does that, and as a backup, we hope // that the TreeSet will eventually resort it from other addJob() calls. timeToWait = timeLeft; - break; + + // failsafe - remove and re-add, peek at the next job, + // break and go around again + if (timeToWait > 10*1000 && iter.hasNext()) { + if (_log.shouldLog(Log.WARN)) + _log.warn("Failsafe re-sort job " + j + + " with delay " + DataHelper.formatDuration(timeToWait)); + iter.remove(); + Job nextJob = iter.next(); + _timedJobs.add(j); + long nextTimeLeft = nextJob.getTiming().getStartAfter() - now; + if (timeToWait > nextTimeLeft) { + _log.error("Job " + j + " out of order with job " + nextJob + + " difference of " + DataHelper.formatDuration(timeToWait - nextTimeLeft)); + timeToWait = Math.max(10, nextTimeLeft); + } + } + break; } } if (timeToWait < 0)