Changeset 1368548 for core


Ignore:
Timestamp:
May 4, 2016 11:43:47 AM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
cdafab27
Parents:
cb2790b
Message:

Utils: Fix bug in periodic timers triggered by
a backwards clock shift, caused graphs to be blank
and various router, streaming, and i2ptunnel
degradations over time (ticket #1776)
Log tweaks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/util/SimpleTimer2.java

    rcb2790b r1368548  
    254254
    255255        /** state of the current event.  All access should be under lock. */
    256         private TimedEventState _state;
     256        protected TimedEventState _state;
    257257        /** absolute time this event should run next time. LOCKING: this */
    258258        private long _nextRun;
     
    339339        public synchronized void reschedule(long timeoutMs, boolean useEarliestTime) {
    340340            if (timeoutMs <= 0) {
    341                 if (timeoutMs < 0 && _log.shouldWarn())
    342                     _log.warn("Resched. timeout < 0: " + this + " timeout = " + timeoutMs + " state: " + _state);
     341                if (timeoutMs < 0 && _log.shouldInfo())
     342                    _log.info("Resched. timeout < 0: " + this + " timeout = " + timeoutMs + " state: " + _state);
    343343                timeoutMs = 1;
    344344            }
     
    424424            synchronized(this) {
    425425                if (Thread.currentThread().isInterrupted()) {
    426                     _log.warn("I was interrupted in run, state "+_state+" event "+this);
     426                    if (_log.shouldWarn())
     427                        _log.warn("I was interrupted in run, state "+_state+" event "+this);
    427428                    return;
    428429                }
     
    432433                switch(_state) {
    433434                  case CANCELLED:
     435                      if (_log.shouldInfo())
     436                          _log.info("Not actually running: CANCELLED " + this);
    434437                    return; // goodbye
    435438                  case IDLE:  // fall through
     
    445448                    // proceed, switch to IDLE to reschedule
    446449                    _state = TimedEventState.IDLE;
     450                    if (_log.shouldInfo())
     451                        _log.info("Early execution, Rescheduling for " + difference + " later: " + this);
    447452                    schedule(difference);
    448453                    return;
     
    486491                            if (_rescheduleAfterRun) {
    487492                                _rescheduleAfterRun = false;
     493                                if (_log.shouldInfo())
     494                                    _log.info("Reschedule after run: " + this);
    488495                                schedule(_nextRun - System.currentTimeMillis());
    489496                            }
     
    495502            if (time > 500 && _log.shouldLog(Log.WARN))
    496503                _log.warn(_pool + " event execution took " + time + ": " + this);
     504            else if (_log.shouldDebug())
     505                _log.debug("Execution finished in " + time + ": " + this);
    497506            if (_log.shouldLog(Log.INFO)) {
    498507                 // this call is slow - iterates through a HashMap -
     
    538547     */
    539548    private static abstract class PeriodicTimedEvent extends TimedEvent {
    540         private long _timeoutMs;
     549        private final long _timeoutMs;
    541550       
    542551        /**
     
    557566        public void run() {
    558567            super.run();
    559             schedule(_timeoutMs);
     568            synchronized(this) {
     569                // Task may have rescheduled itself without actually running.
     570                // If we schedule again, it will be stuck in a scheduling loop.
     571                // This happens after a backwards clock shift.
     572                if (_state == TimedEventState.IDLE)
     573                    schedule(_timeoutMs);
     574            }
    560575        }
    561576    }
Note: See TracChangeset for help on using the changeset viewer.