Project

General

Profile

Actions

bug #7106

closed

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

avoid factory.openSession() in CdmRepository

Added by Andreas Kohlbecker over 6 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Highest
Category:
cdmlib
Target version:
Start date:
Due date:
% Done:

100%

Estimated time:
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 WorksformeWolf-Henning Kusber

Actions
Related to EDIT - bug #8160: CdmBeanItemContainerFactory as readonly service beanClosedAndreas Kohlbecker

Actions
Copied to EDIT - bug #8169: avoid factory.openSession() in DaoBaseNewAndreas Müller

Actions
Actions #1

Updated by Andreas Kohlbecker over 6 years ago

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

Updated by Andreas Kohlbecker over 6 years ago

  • Description updated (diff)
Actions #3

Updated by Andreas Müller over 6 years ago

  • Target version changed from Release 4.13 to Release 4.14
Actions #4

Updated by Andreas Kohlbecker over 6 years ago

  • Priority changed from New to Highest
Actions #5

Updated by Andreas Müller over 6 years ago

  • Target version changed from Release 4.14 to Release 5.0
Actions #6

Updated by Andreas Kohlbecker about 6 years ago

  • Target version changed from Release 5.0 to Release 5.1
Actions #7

Updated by Andreas Müller about 6 years ago

  • Target version changed from Release 5.1 to Release 5.2
Actions #8

Updated by Andreas Kohlbecker almost 6 years ago

  • Target version changed from Release 5.2 to Release 5.3
Actions #9

Updated by Andreas Kohlbecker almost 6 years ago

  • Target version changed from Release 5.3 to Release 5.4
Actions #10

Updated by Andreas Kohlbecker almost 6 years ago

  • Target version changed from Release 5.4 to Release 5.5
Actions #11

Updated by Andreas Kohlbecker over 5 years ago

  • Target version changed from Release 5.5 to Release 5.6
Actions #12

Updated by Andreas Kohlbecker over 5 years 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

Actions #13

Updated by Andreas Kohlbecker over 5 years 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

Actions #14

Updated by Andreas Kohlbecker over 5 years ago

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

Updated by Andreas Kohlbecker over 5 years 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.

Actions #16

Updated by Andreas Kohlbecker over 5 years ago

  • Target version changed from Release 5.7 to Release 5.6
Actions #17

Updated by Andreas Kohlbecker over 5 years 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.

Actions #18

Updated by Andreas Kohlbecker over 5 years ago

  • % Done changed from 20 to 30
Actions #19

Updated by Andreas Kohlbecker over 5 years ago

  • Status changed from Feedback to In Progress
Actions #20

Updated by Andreas Kohlbecker over 5 years ago

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

Updated by Andreas Kohlbecker over 5 years ago

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

Updated by Andreas Kohlbecker over 5 years 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

Actions #23

Updated by Andreas Kohlbecker over 5 years ago

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

this issue should be solved now

Actions #24

Updated by Andreas Kohlbecker over 5 years ago

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

Also available in: Atom PDF