From c5e10ad2df36033a2c62bd6aa37b4f36d89430e5 Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 24 Jan 2013 21:11:07 +0100 Subject: [PATCH] add logging to LARS so bugs can actually be found, see #2950 --- .../test/scala/akka/actor/SchedulerSpec.scala | 33 ++++++++++--------- .../src/main/scala/akka/actor/Scheduler.scala | 15 +++++++-- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/actor/SchedulerSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/SchedulerSpec.scala index 108973ae21..416eff3078 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/SchedulerSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/SchedulerSpec.scala @@ -236,6 +236,18 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit n * 1000.0 / (System.nanoTime - startTime).nanos.toMillis must be(4.4 plusOrMinus 0.3) } + "handle timeouts equal to multiple of wheel period" taggedAs TimingTest in { + val timeout = 3200 milliseconds + val barrier = TestLatch() + import system.dispatcher + val job = system.scheduler.scheduleOnce(timeout)(barrier.countDown()) + try { + Await.ready(barrier, 5000 milliseconds) + } finally { + job.cancel() + } + } + "survive being stressed without cancellation" taggedAs TimingTest in { val r = ThreadLocalRandom.current() val N = 100000 @@ -258,6 +270,10 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit } } } +} + +class DefaultSchedulerSpec extends AkkaSpec(SchedulerSpec.testConf) with SchedulerSpec { + private val cancellables = new ConcurrentLinkedQueue[Cancellable]() "A HashedWheelTimer" must { @@ -273,22 +289,7 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit job.cancel() } - "handle timeouts equal to multiple of wheel period" taggedAs TimingTest in { - val timeout = 3200 milliseconds - val barrier = TestLatch() - import system.dispatcher - val job = system.scheduler.scheduleOnce(timeout)(barrier.countDown()) - try { - Await.ready(barrier, 5000 milliseconds) - } finally { - job.cancel() - } - } } -} - -class DefaultSchedulerSpec extends AkkaSpec(SchedulerSpec.testConf) with SchedulerSpec { - private val cancellables = new ConcurrentLinkedQueue[Cancellable]() def collectCancellable(c: Cancellable): Cancellable = { cancellables.add(c) @@ -485,7 +486,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev prb.ref ! ns try time += lbq.take() catch { - case _: InterruptedException ⇒ + case _: InterruptedException ⇒ Thread.currentThread.interrupt() } } } diff --git a/akka-actor/src/main/scala/akka/actor/Scheduler.scala b/akka-actor/src/main/scala/akka/actor/Scheduler.scala index e64d0e18e6..e3be799fb2 100644 --- a/akka-actor/src/main/scala/akka/actor/Scheduler.scala +++ b/akka-actor/src/main/scala/akka/actor/Scheduler.scala @@ -346,9 +346,18 @@ class LightArrayRevolverScheduler(config: Config, try nextTick() catch { case t: Throwable ⇒ - val thread = threadFactory.newThread(this) - try thread.start() - finally timerThread = thread + log.error(t, "exception on LARS’ timer thread") + stopped.get match { + case null ⇒ + val thread = threadFactory.newThread(this) + log.info("starting new LARS thread") + try thread.start() + catch { + case e: Throwable ⇒ log.error(e, "LARS cannot start new thread, ship’s going down!") + } + timerThread = thread + case x ⇒ x success clearAll() + } throw t } @tailrec final def nextTick(): Unit = {