Details
-
Bug
-
Resolution: Fixed
-
Critical
-
1.1.1, 1.2 M1
-
None
Description
Anca noticed while working on XWatch that sometimes a "session is closed" exception is thrown when updating the feeds.
org.hibernate.SessionException: Session is closed! at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:50) at org.hibernate.impl.SessionImpl.setFlushMode(SessionImpl.java:1271) at com.xpn.xwiki.store.XWikiHibernateBaseStore.getSession(XWikiHibernateBaseStore.java:155) at com.xpn.xwiki.store.XWikiHibernateBaseStore.beginTransaction(XWikiHibernateBaseStore.java:595) at com.xpn.xwiki.store.XWikiHibernateBaseStore.beginTransaction(XWikiHibernateBaseStore.java:568) at com.xpn.xwiki.store.XWikiHibernateStore.searchDocumentsNamesInternal(XWikiHibernateStore.java:1825) at com.xpn.xwiki.store.XWikiHibernateStore.searchDocumentsNames(XWikiHibernateStore.java:1811) at com.xpn.xwiki.store.XWikiHibernateStore.searchDocumentsNames(XWikiHibernateStore.java:2231) at com.xpn.xwiki.store.XWikiCacheStore.searchDocumentsNames(XWikiCacheStore.java:200) at com.xpn.xwiki.plugin.feed.FeedPlugin.updateFeedsInSpace(FeedPlugin.java:310) at com.xpn.xwiki.plugin.feed.UpdateThread.update(UpdateThread.java:82) at com.xpn.xwiki.plugin.feed.UpdateThread.run(UpdateThread.java:56) at java.lang.Thread.run(Thread.java:619)
From the above stacktrace, I think that the problem is caused by the fact that at some point the context object is cloned along with its data members, including the session object; this object is closed in another thread, and the reference is deleted from that context object, but it still exists in the context stored in the current thread.
The proper fix would be to rethink the way the context is stored in background threads, but an easy workaround is to catch this particular exception.