From 952a56c53747e11af4b1857b4c2f2c6aa18976b2 Mon Sep 17 00:00:00 2001 From: zzz Date: Fri, 8 Nov 2013 14:34:33 +0000 Subject: [PATCH] JobQueue: Log a warning if a job is scheduled too far in the future, to catch bugs like the one in -7 where requeue() is called with an absolute time instead of a delay --- router/java/src/net/i2p/router/JobQueue.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/router/java/src/net/i2p/router/JobQueue.java b/router/java/src/net/i2p/router/JobQueue.java index b0630a837..ffe74725a 100644 --- a/router/java/src/net/i2p/router/JobQueue.java +++ b/router/java/src/net/i2p/router/JobQueue.java @@ -13,6 +13,7 @@ import java.io.Writer; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.Date; import java.util.Iterator; import java.util.Map; import java.util.TreeSet; @@ -161,10 +162,17 @@ public class JobQueue { //if (job instanceof JobImpl) // ((JobImpl)job).addedToQueue(); - long numReady = 0; + long numReady; boolean alreadyExists = false; boolean dropped = false; // getNext() is now outside the jobLock, is that ok? + long now = _context.clock().now(); + long start = job.getTiming().getStartAfter(); + if (start > now + 3*24*60*60*1000L) { + // catch bugs, Job.requeue() argument is a delay not a time + if (_log.shouldLog(Log.WARN)) + _log.warn("Scheduling job far in the future: " + (new Date(start)) + ' ' + job); + } synchronized (_jobLock) { if (_readyJobs.contains(job)) alreadyExists = true; @@ -184,9 +192,9 @@ public class JobQueue { dropped = true; } else { if (!alreadyExists) { - if (job.getTiming().getStartAfter() <= _context.clock().now()) { + if (start <= now) { // don't skew us - its 'start after' its been queued, or later - job.getTiming().setStartAfter(_context.clock().now()); + job.getTiming().setStartAfter(now); if (job instanceof JobImpl) ((JobImpl)job).madeReady(); _readyJobs.offer(job); @@ -194,7 +202,7 @@ public class JobQueue { _timedJobs.add(job); // only notify for _timedJobs, as _readyJobs does not use that lock // only notify if sooner, to reduce contention - if (job.getTiming().getStartAfter() < _nextPumperRun) + if (start < _nextPumperRun) _jobLock.notifyAll(); } }