Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0024421Openbravo ERPA. Platformpublic2013-07-29 12:262013-09-27 14:21
alostale 
alostale 
normalmajorrandom
closedfixed 
5
 
3.0MP283.0MP28 
AugustoMauch
Core
No
0024421: ApplicationDictionaryCachedStructures is not thread safe
ApplicationDictionaryCachedStructures with @SessionScoped has some potential issues when it is accessed concurrently by several threads:

1. It caches BaseOBObject with uninitialized proxies. BaseOBObject are attached to the Hibernate session of the thread that did the request. In case Thread-1 caches one of these objects and closes it's session, and later Thread-2 gets this object and touches any of its uninitialized proxies, org.hibernate.LazyInitializationException exception is thrown, causing FIC not to work properly, user can perceive this by hieratical behavior when working in Opebravo (such as not loading default values when creating new records...)
2. In case Thread-2 gets the object before Thread-1 is done, the object's session is still alive. If at this point, the 2 threads try to concurrently load any of the proxied properties (even they are different ones). Different errors can happen, mainly due to StatefulPersistenceContext using non synchronized HashMap, these error can be NPE, org.hibernate.AssertionFailure: possible non-threadsafe access to the session, java.util.ConcurrentModificationException, org.hibernate.LazyInitializationException: illegal access to loading collection or even to get a processor stuck with 100% CPU usage in HashMap.put or HashMap.get caused by trying to access to an inconsistent Map [1][2].
3. (This case is theoretical as it has not been seen/reported so far). ApplicationDictionaryCachedStructures keeps cache in non synchronized HashMaps which can lead to similar consequences than described in issue 2, in case they are concurrently structurally modified [3].

Note this to happen requires to have concurrent threads in the same session calling FIC.


[1] https://hibernate.atlassian.net/browse/HHH-6414 [^]
[2] https://forum.hibernate.org/viewtopic.php?f=1&t=980460 [^]
[3] http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html [^]
The main candidate to cause this is Business Partner window, because main and Customer tabs are working with the same table and customer tab is single record. When a record is selected in header, FIC request is done for it and immediately another request for it's customer tab.
-Completely initialize cached BaseOBObject when first requested.
-This initialization needs to be synchronized in order to be always correctly completed
-Prevent non synchronized Maps structural modifications in ApplicationDictionaryCachedStructures
No tags attached.
related to defect 0024326 closed alostale Openbravo ERP Suboptimal parent tab getter for root tabs 
related to defect 0024412 closed alostale Openbravo ERP Random failures in FIC 
related to defect 00253103.0PR14Q2 closed alostale Openbravo ERP Java processes locked on tomcat 
related to defect 0026664 closed alostale Openbravo ERP Useless ConnectionProvider caching in ApplicationDictionaryCachedStructures 
related to defect 0028519 closed AugustoMauch Openbravo ERP Java-thread apparently deadlocking in OrganizationStructureProvider.initialize 
related to defect 0029754 closed marvintm Retail Modules Concurrent execution of the method generateStaticResources locks the system 
? 24421.export (22,939) 2013-07-30 10:37
https://issues.openbravo.com/file_download.php?file_id=6296&type=bug
Issue History
2013-07-29 12:26alostaleNew Issue
2013-07-29 12:26alostaleAssigned To => AugustoMauch
2013-07-29 12:26alostaleModules => Core
2013-07-29 12:26alostaleTriggers an Emergency Pack => No
2013-07-29 12:27alostaleRelationship addedrelated to 0024326
2013-07-29 12:28alostaleRelationship addedrelated to 0024412
2013-07-29 12:31alostaleProposed Solution updated
2013-07-29 12:36alostaleDescription Updatedbug_revision_view_page.php?rev_id=4919#r4919
2013-07-29 12:36alostaleTarget Version => 3.0MP27
2013-07-29 13:10egoitzIssue Monitored: egoitz
2013-07-29 14:22alostaleAssigned ToAugustoMauch => alostale
2013-07-30 10:37alostaleFile Added: 24421.export
2013-07-30 10:37alostaleNote Added: 0060368
2013-07-30 10:38alostaleNote Added: 0060369
2013-08-20 12:10AugustoMauchTarget Version3.0MP27 => 3.0MP28
2013-09-24 17:49hgbotCheckin
2013-09-24 17:49hgbotNote Added: 0061369
2013-09-24 17:49hgbotStatusnew => resolved
2013-09-24 17:49hgbotResolutionopen => fixed
2013-09-24 17:49hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/d40d287ea91a0c156f9087d2d00fa03dd579a543 [^]
2013-09-24 17:49alostaleReview Assigned To => AugustoMauch
2013-09-25 19:56hudsonbotCheckin
2013-09-25 19:56hudsonbotNote Added: 0061393
2013-09-27 14:21AugustoMauchNote Added: 0061451
2013-09-27 14:21AugustoMauchStatusresolved => closed
2013-09-27 14:21AugustoMauchFixed in Version => 3.0MP28
2014-03-21 10:48alostaleRelationship addedrelated to 0025310
2014-05-22 14:52alostaleRelationship addedrelated to 0026664
2015-01-05 11:16shuehnerRelationship addedrelated to 0028519
2015-04-30 18:07egoitzRelationship addedrelated to 0029754

Notes
(0060368)
alostale   
2013-07-30 10:37   
Attached fix
(0060369)
alostale   
2013-07-30 10:38   
Included within the fix jUnit test cases to verify it
(0061369)
hgbot   
2013-09-24 17:49   
Repository: erp/devel/pi
Changeset: d40d287ea91a0c156f9087d2d00fa03dd579a543
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Tue Jul 30 10:36:44 2013 +0200
URL: http://code.openbravo.com/erp/devel/pi/rev/d40d287ea91a0c156f9087d2d00fa03dd579a543 [^]

fixed bug 24421, fixed bug 24326: ADCachedStructures thread safe issues

-getTab now completely initializes all tabs in the window
-it is now synchronized

Added test cases to check it

---
M modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ApplicationDictionaryCachedStructures.java
M modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelUtils.java
M src-test/org/openbravo/test/AllAntTaskTests.java
A src-test/org/openbravo/test/base/HiddenObjectHelper.java
A src-test/org/openbravo/test/dal/ADCachedMultiThreadTest.java
---
(0061393)
hudsonbot   
2013-09-25 19:56   
A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: https://code.openbravo.com/erp/devel/main/rev/a06bf757c7ec [^]

Maturity status: Test
(0061451)
AugustoMauch   
2013-09-27 14:21   
Code reviewed and verified in pi@34a6241c3e04