Opened 5 years ago

Closed 5 years ago

#2195 closed defect (fixed)

"Timer already cancelled" when trying to log in

Reported by: Nicklas Nordborg Owned by: everyone
Priority: major Milestone: BASE 3.15.3
Component: core Version:
Keywords: Cc:

Description

When trying to log in I get an stack trace:

Timer already cancelled.
java.lang.IllegalStateException
...at java.base/java.util.Timer.sched(Timer.java:398)
...at java.base/java.util.Timer.schedule(Timer.java:194)
...at Keyring.reload(Keyring.java:298)
...at Keyring.getAllPermissions(Keyring.java:904)
...at SessionControl.createLoginInfo(SessionControl.java:1062)
...at SessionControl.login(SessionControl.java:474)
...at org.apache.jsp.login_jsp._jspService(login_jsp.java:178)
...at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
...

For some reason the timer used by the BASE core to perform some regular tasks (such as re-loading access permissions for logged in user) has been stopped. Explicit calls for stopping the timer only exists in the Application.stop() method and in this case we wouldn't get the login page at all.

The timer may also be stopped by an uncaught exception being passed out from a tasks run() method. I found this in the Tomcat's log file:

Exception in thread "Base2Core.Timer" java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
  at java.base/java.lang.Thread.start0(Native Method)
  at java.base/java.lang.Thread.start(Thread.java:803)
  at net.sf.basedb.util.timer.ThreadTimerTask.run(ThreadTimerTask.java:104)
  at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
  at java.base/java.util.TimerThread.run(Timer.java:506)

It actually seems like we can't blame any of the actual tasks that has been scheduled, but there is a problem with starting the thread that should execute the task. The OutOfMemoryError is probably also a bit misleading. A quick search on Google returns several hits that indicate that it is more likely related to a limit on the number of threads. So we can probably catch (and log) that situation in our ThreadTimerTask.run() method and prevent the timer from dying.

However, this also means that the task is not executed and if the problem persists it may have other side-effects.

Change History (3)

comment:1 by Nicklas Nordborg, 5 years ago

Milestone: BASE 3.16BASE 3.15.3

comment:2 by Nicklas Nordborg, 5 years ago

In 7755:

References #2195: "Timer already cancelled" when trying to log in

Added try/catch in the ThreadTimerTask implementation. This should prevent the built-in timer in BASE from stopping and hopefully prevent problems caused by that.

comment:3 by Nicklas Nordborg, 5 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.