Derby
  1. Derby
  2. DERBY-5082

ShutdownException in ContextManager.checkInterrupt() during shutdown

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 10.8.1.2
    • Fix Version/s: 10.8.1.2
    • Component/s: Services
    • Labels:
      None
    • Urgency:
      Blocker
    • Issue & fix info:
      Repro attached
    • Bug behavior facts:
      Regression

      Description

      When running the attached repro script, I often (but not always) see a ShutdownException in ContextManager.checkInterrupt() when ij exits and shuts down the Derby engine. ij expects an exception here, but it expects an SQLException, not a ShutdownException.

      1. derby-5082-1a-fix.diff
        1 kB
        Kristian Waagan
      2. test.sql
        0.5 kB
        Knut Anders Hatlen

        Issue Links

          Activity

          Hide
          Knut Anders Hatlen added a comment -

          Attaching repro script. Here's what I see when running it:

          $ java org.apache.derby.tools.ij test.sql
          ij version 10.8
          ij> connect 'jdbc:derby:db;create=true';
          ij> create table t(x int);
          0 rows inserted/updated/deleted
          (...)
          ij> insert into t select * from t;
          22528 rows inserted/updated/deleted
          ij> select count from t where x > 50;
          1
          -----------
          4096

          1 row selected
          ij> Exception in thread "main" org.apache.derby.iapi.error.ShutdownException:
          at org.apache.derby.iapi.services.context.ContextManager.checkInterrupt(ContextManager.java:464)
          at org.apache.derby.iapi.services.context.ContextManager.popContext(ContextManager.java:202)
          at org.apache.derby.iapi.services.context.ContextImpl.popMe(ContextImpl.java:81)
          at org.apache.derby.impl.store.raw.xact.Xact.close(Xact.java:1169)
          at org.apache.derby.impl.store.raw.xact.Xact.destroy(Xact.java:1110)
          at org.apache.derby.impl.store.access.RAMTransaction.destroy(RAMTransaction.java:2030)
          at org.apache.derby.impl.services.daemon.IndexStatisticsDaemonImpl.stop(IndexStatisticsDaemonImpl.java:866)
          at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.stop(DataDictionaryImpl.java:974)
          at org.apache.derby.impl.services.monitor.TopService.stop(TopService.java:443)
          at org.apache.derby.impl.services.monitor.TopService.shutdown(TopService.java:394)
          at org.apache.derby.impl.services.monitor.BaseMonitor.shutdown(BaseMonitor.java:229)
          at org.apache.derby.impl.services.monitor.BaseMonitor.shutdown(BaseMonitor.java:199)
          at org.apache.derby.jdbc.InternalDriver.connect(InternalDriver.java:241)
          at org.apache.derby.jdbc.AutoloadedDriver.connect(AutoloadedDriver.java:144)
          at java.sql.DriverManager.getConnection(DriverManager.java:582)
          at java.sql.DriverManager.getConnection(DriverManager.java:207)
          at org.apache.derby.impl.tools.ij.utilMain.cleanupGo(utilMain.java:429)
          at org.apache.derby.impl.tools.ij.utilMain.go(utilMain.java:262)
          at org.apache.derby.impl.tools.ij.Main.go(Main.java:229)
          at org.apache.derby.impl.tools.ij.Main.mainCore(Main.java:184)
          at org.apache.derby.impl.tools.ij.Main.main(Main.java:75)
          at org.apache.derby.tools.ij.main(ij.java:59)

          Show
          Knut Anders Hatlen added a comment - Attaching repro script. Here's what I see when running it: $ java org.apache.derby.tools.ij test.sql ij version 10.8 ij> connect 'jdbc:derby:db;create=true'; ij> create table t(x int); 0 rows inserted/updated/deleted (...) ij> insert into t select * from t; 22528 rows inserted/updated/deleted ij> select count from t where x > 50; 1 ----------- 4096 1 row selected ij> Exception in thread "main" org.apache.derby.iapi.error.ShutdownException: at org.apache.derby.iapi.services.context.ContextManager.checkInterrupt(ContextManager.java:464) at org.apache.derby.iapi.services.context.ContextManager.popContext(ContextManager.java:202) at org.apache.derby.iapi.services.context.ContextImpl.popMe(ContextImpl.java:81) at org.apache.derby.impl.store.raw.xact.Xact.close(Xact.java:1169) at org.apache.derby.impl.store.raw.xact.Xact.destroy(Xact.java:1110) at org.apache.derby.impl.store.access.RAMTransaction.destroy(RAMTransaction.java:2030) at org.apache.derby.impl.services.daemon.IndexStatisticsDaemonImpl.stop(IndexStatisticsDaemonImpl.java:866) at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.stop(DataDictionaryImpl.java:974) at org.apache.derby.impl.services.monitor.TopService.stop(TopService.java:443) at org.apache.derby.impl.services.monitor.TopService.shutdown(TopService.java:394) at org.apache.derby.impl.services.monitor.BaseMonitor.shutdown(BaseMonitor.java:229) at org.apache.derby.impl.services.monitor.BaseMonitor.shutdown(BaseMonitor.java:199) at org.apache.derby.jdbc.InternalDriver.connect(InternalDriver.java:241) at org.apache.derby.jdbc.AutoloadedDriver.connect(AutoloadedDriver.java:144) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:207) at org.apache.derby.impl.tools.ij.utilMain.cleanupGo(utilMain.java:429) at org.apache.derby.impl.tools.ij.utilMain.go(utilMain.java:262) at org.apache.derby.impl.tools.ij.Main.go(Main.java:229) at org.apache.derby.impl.tools.ij.Main.mainCore(Main.java:184) at org.apache.derby.impl.tools.ij.Main.main(Main.java:75) at org.apache.derby.tools.ij.main(ij.java:59)
          Hide
          Rick Hillegas added a comment -

          Marking this as a blocker for 10.8.1 because I think this regression is likely to affect a lot of users.

          Show
          Rick Hillegas added a comment - Marking this as a blocker for 10.8.1 because I think this regression is likely to affect a lot of users.
          Hide
          Knut Anders Hatlen added a comment -

          While running the repro script, I've also seen this exception printed to the console:

          Exception in thread "index-stat-thread" org.apache.derby.iapi.error.ShutdownException:
          at org.apache.derby.iapi.services.context.ContextService.getFactory(ContextService.java:210)
          at org.apache.derby.impl.services.daemon.IndexStatisticsDaemonImpl.run(IndexStatisticsDaemonImpl.java:700)
          at java.lang.Thread.run(Thread.java:619)

          ij didn't error out in that case, though.

          Show
          Knut Anders Hatlen added a comment - While running the repro script, I've also seen this exception printed to the console: Exception in thread "index-stat-thread" org.apache.derby.iapi.error.ShutdownException: at org.apache.derby.iapi.services.context.ContextService.getFactory(ContextService.java:210) at org.apache.derby.impl.services.daemon.IndexStatisticsDaemonImpl.run(IndexStatisticsDaemonImpl.java:700) at java.lang.Thread.run(Thread.java:619) ij didn't error out in that case, though.
          Hide
          Kristian Waagan added a comment - - edited

          I extracted one of the istat bug reports (the one with the factory call) and created DERBY-5088.

          Show
          Kristian Waagan added a comment - - edited I extracted one of the istat bug reports (the one with the factory call) and created DERBY-5088 .
          Hide
          Kristian Waagan added a comment -

          Attached patch 1a, which fixes the bug with a ShutdownException raised in ContextManager by avoiding to destroy the tx if the database is shut down. Also, if the transaction is being destroyed, catch ShutdownException in case someone shuts down the database under our feet. This is already done in the main processing loop if the worker thread detects that the daemon has been stopped.

          Since the patch is so small and isolated, I committed it right away with revision 1076462.

          The coming patch for DERBY-5088 will be larger, so I'll need to run more tests before committing.

          Show
          Kristian Waagan added a comment - Attached patch 1a, which fixes the bug with a ShutdownException raised in ContextManager by avoiding to destroy the tx if the database is shut down. Also, if the transaction is being destroyed, catch ShutdownException in case someone shuts down the database under our feet. This is already done in the main processing loop if the worker thread detects that the daemon has been stopped. Since the patch is so small and isolated, I committed it right away with revision 1076462. The coming patch for DERBY-5088 will be larger, so I'll need to run more tests before committing.
          Hide
          Kristian Waagan added a comment -

          I can't reproduce the bug with the fix applied, would be nice if others gave the repro a try too (it doesn't take long to run, but it is wise to delete the database between the runs).
          I didn't see the DERBY-5088 either, but that must be because the timing is different on my machine.

          Show
          Kristian Waagan added a comment - I can't reproduce the bug with the fix applied, would be nice if others gave the repro a try too (it doesn't take long to run, but it is wise to delete the database between the runs). I didn't see the DERBY-5088 either, but that must be because the timing is different on my machine.
          Hide
          Knut Anders Hatlen added a comment -

          Thanks for fixing this, Kristian! I've run the repro script 50 times without seeing the exception. It used to see it on every other run or so, so it appears to be fixed. Closing the bug.

          Show
          Knut Anders Hatlen added a comment - Thanks for fixing this, Kristian! I've run the repro script 50 times without seeing the exception. It used to see it on every other run or so, so it appears to be fixed. Closing the bug.

            People

            • Assignee:
              Kristian Waagan
              Reporter:
              Knut Anders Hatlen
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development