Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-9597

The database is closed before the components are disposed

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 5.2
    • Fix Version/s: None
    • Labels:
      None
    • Difficulty:
      Unknown
    • Documentation:
      N/A
    • Documentation in Release Notes:
      N/A
    • Similar issues:

      Description

      When the server is stopped XWikiServletContextListener is called which does the following:

      1. Fires the ApplicationStoppedEvent
      2. Destroys the deprecated ApplicationContext
      3. Dispose the components

      Currently the default XWiki store, XWikiHibernateStore, is closed by HibernateShutdownEventListener when the ApplicationStoppedEvent is fired, so before the components are disposed. This is a problem for components like Solr indexer which starts threads that use the database and that start throwing exception as soon as the database is closed. Obviously the Solr indexer threads are stopped after the database is closed, when the component is disposed.

      Closing the Solr indexer threads when ApplicationStoppedEvent is fired doesn't fix the problem if the HibernateShutdownEventListener is called before. Moreover 'disposing' a component when ApplicationStoppedEvent is fired is not practical because the component cannot listen to the event: you need a different class and you need to expose some API to the listener.

      Here's an example of the exceptions that are thrown is the database is closed too early:

      2013-10-25 16:52:03,667 [XWiki Solr resolve thread] WARN  o.x.s.s.i.DefaultSolrIndexer   - Failed to apply operation [INDEX] on root reference [xwiki:Main.Spaces] 
      org.xwiki.search.solr.internal.api.SolrIndexerException: Failed to get document [xwiki:Main.Spaces]
      	at org.xwiki.search.solr.internal.reference.DocumentSolrReferenceResolver.getReferences(DocumentSolrReferenceResolver.java:102) ~[xwiki-platform-search-solr-api-5.3-SNAPSHOT.jar:na]
      	at org.xwiki.search.solr.internal.reference.DocumentSolrReferenceResolver.getReferences(DocumentSolrReferenceResolver.java:55) ~[xwiki-platform-search-solr-api-5.3-SNAPSHOT.jar:na]
      	at org.xwiki.search.solr.internal.reference.DefaultSolrReferenceResolver.getReferences(DefaultSolrReferenceResolver.java:164) ~[xwiki-platform-search-solr-api-5.3-SNAPSHOT.jar:na]
      	at org.xwiki.search.solr.internal.DefaultSolrIndexer$Resolver.runInternal(DefaultSolrIndexer.java:204) ~[xwiki-platform-search-solr-api-5.3-SNAPSHOT.jar:na]
      	at com.xpn.xwiki.util.AbstractXWikiRunnable.run(AbstractXWikiRunnable.java:131) ~[xwiki-platform-legacy-oldcore-5.3-20131024.142610-44.jar:na]
      	at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
      Caused by: com.xpn.xwiki.XWikiException: Error number 3202 in 3: Exception while reading document [xwiki:Main.Spaces]
      	at com.xpn.xwiki.store.XWikiHibernateStore.loadXWikiDoc(XWikiHibernateStore.java:927) ~[xwiki-platform-legacy-oldcore-5.3-20131024.142610-44.jar:na]
      	at com.xpn.xwiki.store.XWikiCacheStore.loadXWikiDoc(XWikiCacheStore.java:290) ~[xwiki-platform-legacy-oldcore-5.3-20131024.142610-44.jar:na]
      	at com.xpn.xwiki.XWiki.getDocument(XWiki.java:1356) ~[xwiki-platform-legacy-oldcore-5.3-20131024.142610-44.jar:na]
      	at com.xpn.xwiki.XWiki.getDocument(XWiki.java:1403) ~[xwiki-platform-legacy-oldcore-5.3-20131024.142610-44.jar:na]
      	at org.xwiki.search.solr.internal.reference.AbstractSolrReferenceResolver.getDocument(AbstractSolrReferenceResolver.java:77) ~[xwiki-platform-search-solr-api-5.3-SNAPSHOT.jar:na]
      	at org.xwiki.search.solr.internal.reference.DocumentSolrReferenceResolver.getReferences(DocumentSolrReferenceResolver.java:100) ~[xwiki-platform-search-solr-api-5.3-SNAPSHOT.jar:na]
      	... 5 common frames omitted
      Caused by: java.lang.NullPointerException: null
      	at com.xpn.xwiki.store.DBCPConnectionProvider.getConnection(DBCPConnectionProvider.java:225) ~[xwiki-platform-legacy-oldcore-5.3-20131024.142610-44.jar:na]
      	at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
      	at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
      	at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
      	at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
      	at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final]
      	at com.xpn.xwiki.store.XWikiHibernateBaseStore.beginTransaction(XWikiHibernateBaseStore.java:864) ~[xwiki-platform-legacy-oldcore-5.3-20131024.142610-44.jar:na]
      	at com.xpn.xwiki.store.XWikiHibernateBaseStore.beginTransaction(XWikiHibernateBaseStore.java:804) ~[xwiki-platform-legacy-oldcore-5.3-20131024.142610-44.jar:na]
      	at com.xpn.xwiki.store.XWikiHibernateStore.loadXWikiDoc(XWikiHibernateStore.java:799) ~[xwiki-platform-legacy-oldcore-5.3-20131024.142610-44.jar:na]
      	... 10 common frames omitted
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vmassol Vincent Massol
                Reporter:
                mflorea Marius Dumitru Florea
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Date of First Response: