Project

General

Profile

bug #7106

bug #7105: potential dangerous use of factory.openSession()

avoid factory.openSession() in CdmRepository

Added by Andreas Kohlbecker over 1 year ago. Updated 4 months ago.

Status:
Closed
Priority:
Highest
Category:
cdmlib
Target version:
Start date:
12/04/2017
Due date:
% Done:

100%

Severity:
normal
Found in Version:

Description

In CdmRepository using factory.openSession() is plain wrong, the HibernateTransactionManger should be used instead.


Related issues

Related to Edit - bug #8132: phycobank cdm-server instance problems with db connections New 02/22/2019
Related to Edit - bug #8160: CdmBeanItemContainerFactory as readonly service bean Closed 03/04/2019
Copied to Edit - bug #8169: avoid factory.openSession() in DaoBase New 12/04/2017

Associated revisions

Revision 3a973027 (diff)
Added by Andreas Kohlbecker 6 months ago

ref #7106 logging if the worse case is actually happening

Revision 568fb7dc (diff)
Added by Andreas Kohlbecker 6 months ago

ref #7106 logging stacktrace with 'Opening new session in turn of a HibernateException'

Revision ff628107 (diff)
Added by Andreas Kohlbecker 6 months ago

ref #7106 throwing Exception instead of unintentially creating unmanaged new session

Revision 6d6ae033 (diff)
Added by Andreas Kohlbecker 6 months ago

ref #7106 logging unintentially creation of unmanaged new session in DaoBase with stacktrace

Revision b7647a99 (diff)
Added by Andreas Kohlbecker 6 months ago

ref #7106 using new CdmRepository.clearSession() method

Revision 998a72e0 (diff)
Added by Andreas Kohlbecker 6 months ago

ref #7106 refactoring CdmStore in turn of changed CdmRepository.getSession()
- CdmStore as Spring bean
- CdmStore managed transactions and sessions properly

Revision 80595b0d (diff)
Added by Andreas Kohlbecker 6 months ago

ref #7106 proper transaction management in turn of solving the problem in CdmRepository.getSession()

Revision d617562f (diff)
Added by Andreas Kohlbecker 4 months ago

ref #7106 logging if the worse case is actually happening

Revision bce4a336 (diff)
Added by Andreas Kohlbecker 4 months ago

ref #7106 logging stacktrace with 'Opening new session in turn of a HibernateException'

Revision 528d4496 (diff)
Added by Andreas Kohlbecker 4 months ago

ref #7106 throwing Exception instead of unintentially creating unmanaged new session

Revision afe10f33 (diff)
Added by Andreas Kohlbecker 4 months ago

ref #7106 logging unintentially creation of unmanaged new session in DaoBase with stacktrace

Revision ae4ccce0 (diff)
Added by Andreas Kohlbecker 4 months ago

ref #7106 proper transaction management in turn of solving the problem in CdmRepository.getSession()

History

#1 Updated by Andreas Kohlbecker over 1 year ago

  • Subject changed from avoid factory.openSession() in CdmRepository to avoid factory.openSession() in CdmRepository and in DaoBase
  • Description updated (diff)

#2 Updated by Andreas Kohlbecker over 1 year ago

  • Description updated (diff)

#3 Updated by Andreas Müller over 1 year ago

  • Target version changed from Release 4.13 to Release 4.14

#4 Updated by Andreas Kohlbecker over 1 year ago

  • Priority changed from New to Highest

#5 Updated by Andreas Müller over 1 year ago

  • Target version changed from Release 4.14 to Release 5.0

#6 Updated by Andreas Kohlbecker over 1 year ago

  • Target version changed from Release 5.0 to Release 5.1

#7 Updated by Andreas Müller about 1 year ago

  • Target version changed from Release 5.1 to Release 5.2

#8 Updated by Andreas Kohlbecker about 1 year ago

  • Target version changed from Release 5.2 to Release 5.3

#9 Updated by Andreas Kohlbecker 12 months ago

  • Target version changed from Release 5.3 to Release 5.4

#10 Updated by Andreas Kohlbecker 10 months ago

  • Target version changed from Release 5.4 to Release 5.5

#11 Updated by Andreas Kohlbecker 7 months ago

  • Target version changed from Release 5.5 to Release 5.6

#12 Updated by Andreas Kohlbecker 6 months ago

  • Status changed from New to Feedback
  • Target version changed from Release 5.6 to Release 5.7

I am modifying the logging in mentioned case to allow us checking in the server logs if this case is actually happening.

 try {
            session = factory.getCurrentSession();
        } catch (HibernateException e) {
            logger.warn("[#7106] Opening new session in turn of a HibernateException: " + e.getMessage());
            session = factory.openSession();
        }

we need check the logs after a while, therefore i moved this issue to the 5.7 release milestone

#13 Updated by Andreas Kohlbecker 6 months ago

In a locally running cdmserver started vi the eclipse launcher cdm-server - start from war multiple occurrences can be observed when navigating the vaadin registration UI:

=================================================================
[phycobank] 16:52:20,776 INFO [qtp709865851-21][co.va.sp.se.SpringUIProvider] - Checking the application context for Vaadin UIs
[phycobank] 16:52:20,780 INFO [qtp709865851-21][co.va.sp.se.SpringUIProvider] - Found Vaadin UI [eu.etaxonomy.cdm.vaadin.ui.ConceptRelationshipUI]
[phycobank] 16:52:20,780 DEBUG [qtp709865851-21][co.va.sp.se.SpringUIProvider] - Mapping Vaadin UI [eu.etaxonomy.cdm.vaadin.ui.ConceptRelationshipUI] to path [/concept]
[phycobank] 16:52:20,780 INFO [qtp709865851-21][co.va.sp.se.SpringUIProvider] - Found Vaadin UI [eu.etaxonomy.cdm.vaadin.ui.RegistrationUI]
[phycobank] 16:52:20,780 DEBUG [qtp709865851-21][co.va.sp.se.SpringUIProvider] - Mapping Vaadin UI [eu.etaxonomy.cdm.vaadin.ui.RegistrationUI] to path [/registration]
[phycobank] 16:52:20,780 INFO [qtp709865851-21][co.va.sp.se.SpringUIProvider] - Found Vaadin UI [eu.etaxonomy.cdm.vaadin.ui.DistributionStatusUI]
[phycobank] 16:52:20,780 DEBUG [qtp709865851-21][co.va.sp.se.SpringUIProvider] - Mapping Vaadin UI [eu.etaxonomy.cdm.vaadin.ui.DistributionStatusUI] to path [/distribution]
[phycobank] 16:52:20,780 INFO [qtp709865851-21][co.va.sp.se.SpringUIProvider] - Found Vaadin UI [eu.etaxonomy.cdm.vaadin.ui.StatusEditorUI]
[phycobank] 16:52:20,780 DEBUG [qtp709865851-21][co.va.sp.se.SpringUIProvider] - Mapping Vaadin UI [eu.etaxonomy.cdm.vaadin.ui.StatusEditorUI] to path [/editstatus]
[phycobank] 16:52:20,804 DEBUG [qtp709865851-21][co.va.sp.se.SpringUIProvider] - Creating directory [/home/andreas/.cdmLibrary/server/cdm-webapp-5.6.0-SNAPSHOT-/VAADIN/themes/edit-valo]
[phycobank] 16:52:21,156 DEBUG [qtp709865851-38][co.va.sp.se.SpringUIProvider] - Creating a new UI bean of class [eu.etaxonomy.cdm.vaadin.ui.RegistrationUI] with identifier [UI:0]
Mar 06, 2019 4:52:21 PM com.vaadin.server.VaadinServlet serveStaticResourcesInVAADIN
INFO: Requested resource [/VAADIN/themes/edit-valo/favicon.ico] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.
[phycobank] 16:52:23,357 DEBUG [qtp709865851-38][co.va.sp.se.SpringUIProvider] - Looking for a SpringViewDisplay bean based on bean level annotations
[phycobank] 16:52:23,370 DEBUG [qtp709865851-38][co.va.sp.se.SpringUIProvider] - No view display defined for the UI null
[phycobank] 16:52:23,928 DEBUG [qtp709865851-38][eu.et.cd.va.pe.AccessRestrictedViewControlBean] - allowing view by fall through, no check performed
[phycobank] 16:52:28,737 DEBUG [qtp709865851-36][eu.et.cd.va.pe.AccessRestrictedViewControlBean] - allowing view by fall through, no check performed
[phycobank] 16:52:45,928 DEBUG [qtp709865851-21][eu.et.cd.va.vi.LoginPresenter] - user 'curator' authenticated
[phycobank] 16:52:45,928 DEBUG [qtp709865851-21][eu.et.cd.va.vi.LoginPresenter] - redirecting to dashboard
[phycobank] 16:52:45,934 DEBUG [qtp709865851-21][eu.et.cd.va.pe.AccessRestrictedViewControlBean] - allowing view by fall through, no check performed
[phycobank] 16:52:47,739 DEBUG [qtp709865851-20][eu.et.cd.va.pe.AccessRestrictedViewControlBean] - Access to view ListViewBean allowed
[phycobank] 16:52:47,746 WARN [qtp709865851-20][eu.et.cd.ap.ap.CdmRepository] - [#7106] Opening new session in turn of a HibernateException: Could not obtain transaction-synchronized Session for current thread
[phycobank] 16:52:47,746 WARN [qtp709865851-20][eu.et.cd.ap.ap.CdmRepository] - [#7106] Opening new session in turn of a HibernateException: Could not obtain transaction-synchronized Session for current thread
[phycobank] 16:53:33,771 DEBUG [qtp709865851-20][eu.et.cd.va.pe.AccessRestrictedViewControlBean] - Access to view RegistrationWorksetViewBean allowed
[phycobank] 16:53:33,789 WARN [qtp709865851-20][eu.et.cd.ap.ap.CdmRepository] - [#7106] Opening new session in turn of a HibernateException: Could not obtain transaction-synchronized Session for current thread
[phycobank] 16:53:33,789 WARN [qtp709865851-20][eu.et.cd.ap.ap.CdmRepository] - [#7106] Opening new session in turn of a HibernateException: Could not obtain transaction-synchronized Session for current thread
[phycobank] 16:53:34,970 WARN [qtp709865851-20][ne.sf.eh.co.CacheConfiguration] - Cache: eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkingsetPresenter1037416999 has a maxElementsInMemory of 0. This might lead to performance degradation or OutOfMemoryError at Terracotta client.From Ehcache 2.0 onwards this has been changed to mean a store with no capacity limit. Set it to 1 if you want no elements cached in memory
[phycobank] 16:53:34,970 WARN [qtp709865851-20][ne.sf.eh.co.CacheConfiguration] - Cache: eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkingsetPresenter1037416999 has a maxElementsInMemory of 0. This might lead to performance degradation or OutOfMemoryError at Terracotta client.From Ehcache 2.0 onwards this has been changed to mean a store with no capacity limit. Set it to 1 if you want no elements cached in memory
[phycobank] 16:53:34,975 WARN [qtp709865851-20][ne.sf.eh.co.CacheConfiguration] - Cache: cdmModelGetMethodsCache has a maxElementsInMemory of 0. This might lead to performance degradation or OutOfMemoryError at Terracotta client.From Ehcache 2.0 onwards this has been changed to mean a store with no capacity limit. Set it to 1 if you want no elements cached in memory
[phycobank] 16:53:34,975 WARN [qtp709865851-20][ne.sf.eh.co.CacheConfiguration] - Cache: cdmModelGetMethodsCache has a maxElementsInMemory of 0. This might lead to performance degradation or OutOfMemoryError at Terracotta client.From Ehcache 2.0 onwards this has been changed to mean a store with no capacity limit. Set it to 1 if you want no elements cached in memory
[phycobank] 16:53:35,183 DEBUG [qtp709865851-20][eu.et.cd.va.co.re.RegistrationItemNameAndTypeButtons] - WorkingSet:SPECIMEN_TYPE_DESIGNATION_WORKINGSET>FieldUnit#3bf0f71d-7a1f-410e-a016-0b0fa3cda1df
[phycobank] 16:53:35,246 DEBUG [qtp709865851-20][eu.et.cd.va.co.re.RegistrationItemNameAndTypeButtons] - WorkingSet:SPECIMEN_TYPE_DESIGNATION_WORKINGSET>FieldUnit#32a21a51-a983-4277-8faa-1438bd2bdeeb
[phycobank] 16:53:35,265 DEBUG [qtp709865851-20][eu.et.cd.va.co.re.RegistrationItemNameAndTypeButtons] - WorkingSet:SPECIMEN_TYPE_DESIGNATION_WORKINGSET>FieldUnit#6c79eeb5-ff06-4893-ac6d-715f1ac31942
[phycobank] 16:53:35,284 DEBUG [qtp709865851-20][eu.et.cd.va.co.re.RegistrationItemNameAndTypeButtons] - WorkingSet:SPECIMEN_TYPE_DESIGNATION_WORKINGSET>FieldUnit#61d21b90-f7d8-4ed2-a7bc-7cb0baf33494
[phycobank] 16:53:35,300 DEBUG [qtp709865851-20][eu.et.cd.va.co.re.RegistrationItemNameAndTypeButtons] - WorkingSet:SPECIMEN_TYPE_DESIGNATION_WORKINGSET>FieldUnit#4739391b-ec1c-4292-a620-95d3e35b0542
[phycobank] 16:53:35,310 DEBUG [qtp709865851-20][eu.et.cd.va.co.re.RegistrationItemNameAndTypeButtons] - WorkingSet:SPECIMEN_TYPE_DESIGNATION_WORKINGSET>FieldUnit#7aae8434-94c7-48ba-86c5-20c3dfce2ce0
[phycobank] 16:53:35,319 DEBUG [qtp709865851-20][eu.et.cd.va.co.re.RegistrationItemNameAndTypeButtons] - WorkingSet:SPECIMEN_TYPE_DESIGNATION_WORKINGSET>FieldUnit#d964f982-97a4-4c7e-94f0-0d99ba63110b
[phycobank] 16:54:41,750 WARN [qtp709865851-36][eu.et.cd.ap.ap.CdmRepository] - [#7106] Opening new session in turn of a HibernateException: Could not obtain transaction-synchronized Session for current thread
[phycobank] 16:54:41,750 WARN [qtp709865851-36][eu.et.cd.ap.ap.CdmRepository] - [#7106] Opening new session in turn of a HibernateException: Could not obtain transaction-synchronized Session for current thread
[phycobank] 16:54:42,382 DEBUG [qtp709865851-36][eu.et.va.co.ToManyRelatedEntitiesListSelect] - NULL field at 0,0
[phycobank] 16:54:42,484 DEBUG [qtp709865851-36][eu.et.va.co.ToManyRelatedEntitiesListSelect] - NULL field at 0,0
[phycobank] 16:54:42,731 WARN [qtp709865851-36][eu.et.cd.ap.ap.CdmRepository] - [#7106] Opening new session in turn of a HibernateException: Could not obtain transaction-synchronized Session for current thread
[phycobank] 16:54:42,731 WARN [qtp709865851-36][eu.et.cd.ap.ap.CdmRepository] - [#7106] Opening new session in turn of a HibernateException: Could not obtain transaction-synchronized Session for current thread
...

the same accounts for the testserver as well

#14 Updated by Andreas Kohlbecker 6 months ago

  • Related to bug #8132: phycobank cdm-server instance problems with db connections added

#15 Updated by Andreas Kohlbecker 6 months ago

  • % Done changed from 0 to 20

with the logging of the stacktrace it now becomes clear where the unmanaged sessions are being created:

java.lang.Thread.getStackTrace(Thread.java:1559)
eu.etaxonomy.cdm.api.application.CdmRepository.getSession(CdmRepository.java:506)
eu.etaxonomy.cdm.service.CdmBeanItemContainerFactory.clearSession(CdmBeanItemContainerFactory.java:139)
eu.etaxonomy.cdm.service.CdmBeanItemContainerFactory.buildBeanItemContainer(CdmBeanItemContainerFactory.java:114)
eu.etaxonomy.cdm.api.application.CdmRepository.getSession(CdmRepository.java:506)
eu.etaxonomy.vaadin.mvp.AbstractPresenter.getSession(AbstractPresenter.java:110)
eu.etaxonomy.vaadin.mvp.AbstractPresenter.handleViewEntered(AbstractPresenter.java:177)
java.lang.Thread.getStackTrace(Thread.java:1559)
eu.etaxonomy.cdm.api.application.CdmRepository.getSession(CdmRepository.java:506)
eu.etaxonomy.cdm.service.CdmBeanItemContainerFactory.clearSession(CdmBeanItemContainerFactory.java:139)
eu.etaxonomy.cdm.service.CdmBeanItemContainerFactory.buildTermItemContainer(CdmBeanItemContainerFactory.java:98)
eu.etaxonomy.cdm.service.CdmBeanItemContainerFactory.buildTermItemContainer(CdmBeanItemContainerFactory.java:89)

all these are situations where the the application attempts to clear an existing session, if the CdmRepository.getSession() would return null or throw the HibernateException the client code could handle this situation properly by just doing nothing.

#16 Updated by Andreas Kohlbecker 6 months ago

  • Target version changed from Release 5.7 to Release 5.6

#17 Updated by Andreas Kohlbecker 6 months ago

since February 25th there are only occurrences related to this issue in the log which affected the phycobank code.
We therefore can be pretty sure that a change of CdmRepository.getSession() will not affect other clients.

#18 Updated by Andreas Kohlbecker 6 months ago

  • % Done changed from 20 to 30

#19 Updated by Andreas Kohlbecker 6 months ago

  • Status changed from Feedback to In Progress

#20 Updated by Andreas Kohlbecker 6 months ago

  • Copied to bug #8169: avoid factory.openSession() in DaoBase added

#21 Updated by Andreas Kohlbecker 5 months ago

  • Related to bug #8160: CdmBeanItemContainerFactory as readonly service bean added

#22 Updated by Andreas Kohlbecker 4 months ago

  • Subject changed from avoid factory.openSession() in CdmRepository and in DaoBase to avoid factory.openSession() in CdmRepository

changing the ticket subject since there is now a separate ticket for the DaoBase class: #8169

#23 Updated by Andreas Kohlbecker 4 months ago

  • Status changed from In Progress to Resolved
  • % Done changed from 30 to 50

this issue should be solved now

#24 Updated by Andreas Kohlbecker 4 months ago

  • Status changed from Resolved to Closed
  • % Done changed from 50 to 100

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 40 MB)