Derby
  1. Derby
  2. DERBY-4895

Thread local TableDescriptor#referencedColumnMap is not removed from app threads when Derby is shut down

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 10.5.1.1, 10.5.2.0, 10.5.3.0, 10.6.1.0, 10.6.2.1
    • Fix Version/s: 10.5.3.2, 10.6.2.4, 10.7.1.1
    • Component/s: SQL
    • Labels:
      None
    • Bug behavior facts:
      Regression, Seen in production

      Description

      > This has been seen to cause error messages in TomCat, cf. this quote from a mail on derby-user:
      >
      > http://mail-archives.apache.org/mod_mbox/db-derby-user/201011.mbox/%3C7800E37B639BC345BC2AB40980B7C529180FB525@MERCMBX03R.na.SAS.com%3E
      >
      > SEVERE: The web application [/MyApp] created a ThreadLocal with key of type [org.apache.derby.iapi.sq\
      > l.dictionary.TableDescriptor$1] (value [org.apache.derby.iapi.sql.dictionary.TableDescriptor$1@d133a3])\
      > and a value of type [java.util.WeakHashMap] (value [{=

      {1, 2, 3, 4}

      , =null, =null}]) but failed to remo\
      > ve it when the web application was stopped. This is very likely to create a memory leak.

      1. DERBY-4895_10_5_diff.txt
        7 kB
        Kathey Marsden
      2. derby-4895_10_6_diff.txt
        7 kB
        Kathey Marsden
      3. derby-4895-a.stat
        0.2 kB
        Dag H. Wanvik
      4. derby-4895-a.diff
        7 kB
        Dag H. Wanvik

        Issue Links

          Activity

          Hide
          Dag H. Wanvik added a comment -

          Talked to Knut about this, we may possibly be able to move this map into lcc and avoid the thread local altogether.

          Show
          Dag H. Wanvik added a comment - Talked to Knut about this, we may possibly be able to move this map into lcc and avoid the thread local altogether.
          Hide
          Dag H. Wanvik added a comment -

          Sadly, the lcc isn't necessarily available, cf this assert on finding an lcc from context:

          Caused by: org.apache.derby.shared.common.sanity.AssertFailure: ASSERT FAILED
          at org.apache.derby.shared.common.sanity.SanityManager.ASSERT(SanityManager.java:98)
          at org.apache.derby.iapi.sql.dictionary.TableDescriptor.referencedColumnMapPut(TableDescriptor.java:144)
          at org.apache.derby.iapi.sql.dictionary.TableDescriptor.setReferencedColumnMap(TableDescriptor.java:375)
          at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getTableDescriptor(DataDictionaryImpl.java:2034)
          at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.faultInTabInfo(DataDictionaryImpl.java:9062)
          at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getNonCoreTI(DataDictionaryImpl.java:8865)
          at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.addDescriptor(DataDictionaryImpl.java:1840)
          at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.createSystemProcedureOrFunction(DataDictionaryImpl.java:9823)
          at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.createSystemProcedureOrFunction(DataDictionaryImpl.java:9879)
          at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.create_SYSIBM_procedures(DataDictionaryImpl.java:10584)
          at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.boot(DataDictionaryImpl.java:737)
          at org.apache.derby.impl.services.monitor.BaseMonitor.boot(BaseMonitor.java:1979)
          at org.apache.derby.impl.services.monitor.TopService.bootModule(TopService.java:333)
          at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(BaseMonitor.java:531)
          at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Monitor.java:427)
          at org.apache.derby.impl.db.BasicDatabase.boot(BasicDatabase.java:211)
          at org.apache.derby.impl.services.monitor.BaseMonitor.boot(BaseMonitor.java:1979)
          at org.apache.derby.impl.services.monitor.TopService.bootModule(TopService.java:333)
          at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(BaseMonitor.java:1816)
          at org.apache.derby.impl.services.monitor.BaseMonitor.createPersistentService(BaseMonitor.java:1002)
          at org.apache.derby.iapi.services.monitor.Monitor.createPersistentService(Monitor.java:596)
          at org.apache.derby.impl.jdbc.EmbedConnection.createDatabase(EmbedConnection.java:2528)

          Show
          Dag H. Wanvik added a comment - Sadly, the lcc isn't necessarily available, cf this assert on finding an lcc from context: Caused by: org.apache.derby.shared.common.sanity.AssertFailure: ASSERT FAILED at org.apache.derby.shared.common.sanity.SanityManager.ASSERT(SanityManager.java:98) at org.apache.derby.iapi.sql.dictionary.TableDescriptor.referencedColumnMapPut(TableDescriptor.java:144) at org.apache.derby.iapi.sql.dictionary.TableDescriptor.setReferencedColumnMap(TableDescriptor.java:375) at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getTableDescriptor(DataDictionaryImpl.java:2034) at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.faultInTabInfo(DataDictionaryImpl.java:9062) at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getNonCoreTI(DataDictionaryImpl.java:8865) at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.addDescriptor(DataDictionaryImpl.java:1840) at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.createSystemProcedureOrFunction(DataDictionaryImpl.java:9823) at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.createSystemProcedureOrFunction(DataDictionaryImpl.java:9879) at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.create_SYSIBM_procedures(DataDictionaryImpl.java:10584) at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.boot(DataDictionaryImpl.java:737) at org.apache.derby.impl.services.monitor.BaseMonitor.boot(BaseMonitor.java:1979) at org.apache.derby.impl.services.monitor.TopService.bootModule(TopService.java:333) at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(BaseMonitor.java:531) at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Monitor.java:427) at org.apache.derby.impl.db.BasicDatabase.boot(BasicDatabase.java:211) at org.apache.derby.impl.services.monitor.BaseMonitor.boot(BaseMonitor.java:1979) at org.apache.derby.impl.services.monitor.TopService.bootModule(TopService.java:333) at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(BaseMonitor.java:1816) at org.apache.derby.impl.services.monitor.BaseMonitor.createPersistentService(BaseMonitor.java:1002) at org.apache.derby.iapi.services.monitor.Monitor.createPersistentService(Monitor.java:596) at org.apache.derby.impl.jdbc.EmbedConnection.createDatabase(EmbedConnection.java:2528)
          Hide
          Dag H. Wanvik added a comment -

          It seems that we could possibly ignore calls to td.referencedColumnMapPut(null) if there is no lcc yet, I'll run an experiment with an assert. If so, lcc might still be a workable solution.

          Show
          Dag H. Wanvik added a comment - It seems that we could possibly ignore calls to td.referencedColumnMapPut(null) if there is no lcc yet, I'll run an experiment with an assert. If so, lcc might still be a workable solution.
          Hide
          Dag H. Wanvik added a comment - - edited

          Uploading a patch which replaces the thread local storage of the referencedColumnMap in favor of storing it in the lcc. This should solve the problem seen by the user.
          If several threads use the same connection, they will now share the referencedColumnMap, but the API calls are serialized at the JDBC level, so that's ok.
          If a thread uses several connections, there will now be one map per connection, which is ok, too.

          Regressions ran ok.

          Show
          Dag H. Wanvik added a comment - - edited Uploading a patch which replaces the thread local storage of the referencedColumnMap in favor of storing it in the lcc. This should solve the problem seen by the user. If several threads use the same connection, they will now share the referencedColumnMap, but the API calls are serialized at the JDBC level, so that's ok. If a thread uses several connections, there will now be one map per connection, which is ok, too. Regressions ran ok.
          Hide
          Knut Anders Hatlen added a comment -

          The patch looks good to me. It may be worth adding a comment explaining the assert in referencedColumnMapPut(), though. I tested the patch on Tomcat 7.0.4 and saw that the warning went away when the patch was applied.

          Show
          Knut Anders Hatlen added a comment - The patch looks good to me. It may be worth adding a comment explaining the assert in referencedColumnMapPut(), though. I tested the patch on Tomcat 7.0.4 and saw that the warning went away when the patch was applied.
          Hide
          Dag H. Wanvik added a comment -

          Closing, committed as svn 1033485. Candidate for back-port.

          Show
          Dag H. Wanvik added a comment - Closing, committed as svn 1033485. Candidate for back-port.
          Hide
          Dag H. Wanvik added a comment -

          Thanks for the review, Knut. I added a comment in the commit as you suggested.

          Show
          Dag H. Wanvik added a comment - Thanks for the review, Knut. I added a comment in the commit as you suggested.
          Hide
          Kathey Marsden added a comment -

          Reopen for backport

          Show
          Kathey Marsden added a comment - Reopen for backport
          Hide
          Kathey Marsden added a comment -

          Assigning to myself temporarily for port to 10.5

          Show
          Kathey Marsden added a comment - Assigning to myself temporarily for port to 10.5
          Hide
          Kathey Marsden added a comment -

          This one required some manual merge back to 10.6. Diff attached derby-4895_10_6_diff.txt

          Show
          Kathey Marsden added a comment - This one required some manual merge back to 10.6. Diff attached derby-4895_10_6_diff.txt
          Hide
          Kathey Marsden added a comment -

          Here is the 10.5 patch. Again some manual merge even merging from 10.6. Running tests now.

          Show
          Kathey Marsden added a comment - Here is the 10.5 patch. Again some manual merge even merging from 10.6. Running tests now.
          Hide
          Kathey Marsden added a comment -

          Ported fix to 10.6 and 10.5, reclosing issue.

          Show
          Kathey Marsden added a comment - Ported fix to 10.6 and 10.5, reclosing issue.

            People

            • Assignee:
              Dag H. Wanvik
              Reporter:
              Dag H. Wanvik
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development