[JAVASERVERFACES-2535] UIComponent not thread safe use of facescontext Attributes Created: 10/Oct/12  Updated: 19/Oct/12  Resolved: 19/Oct/12

Status: Closed
Project: javaserverfaces
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Blocker
Reporter: crcerror Assignee: Manfred Riem
Resolution: Invalid Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by JAVASERVERFACES-2544 Endless Loop By Unsynchronized WeakHa... Closed

 Description   

When using @viewScoped beans, if a user post multiple simultaneous requests to the bean there are multiple threads working on the same managed bean.
This causes an issue with the UIComponent class, there in the popComponentFromEL method is an unsafe get() call to a hashmap.

When the server is under a heavy load then some threads get stuck in an infinite loop in the get() method of the Hashmap implementation.

Is this a bug or it is a design choice not to synchronize the access to the contextAttributes hashmap?

details:
Weblogic 10.3.4
Jsf 2.0.6
jvm Oracle JRockit(R) R28.1.0-123-138454-1.6.0_20-20101014-1350-linux-x86_64

– problem method in UIComponent.class ----

private static ComponentStack _getComponentELStack(String keyName, Map<Object, Object> contextAttributes)
{
ComponentStack elStack = (ComponentStack)contextAttributes.get(keyName); <-- unsafe hashmap access, need to synchronize access?

if (elStack == null)

{ elStack = new ComponentStack(); contextAttributes.put(keyName, elStack); }

return elStack;
}

------- stack dump of stuck thread -----

"[STUCK] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'" id=26 idx=0x7c tid=18549 prio=1 alive, native_blocked, daemon

at javax/faces/component/UIComponent.popComponentFromEL(UIComponent.java:1821)[optimized]

at javax/faces/component/UIComponent.popComponentFromEL(UIComponent.java:1846)[inlined]

at javax/faces/component/UIComponentBase.encodeEnd(UIComponentBase.java:884)[optimized]

at com/sun/faces/renderkit/html_basic/HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:308)[inlined]

at com/sun/faces/renderkit/html_basic/GroupRenderer.encodeChildren(GroupRenderer.java:101)[optimized]

at javax/faces/component/UIComponentBase.encodeChildren(UIComponentBase.java:849)[optimized]

at javax/faces/component/UIComponent.encodeAll(UIComponent.java:1648)[optimized]

at com/sun/faces/renderkit/html_basic/CompositeRenderer.encodeChildren(CompositeRenderer.java:75)[optimized]

at javax/faces/component/UIComponentBase.encodeChildren(UIComponentBase.java:849)[optimized]

at com/sun/faces/renderkit/html_basic/HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:300)[inlined]

at com/sun/faces/renderkit/html_basic/GroupRenderer.encodeChildren(GroupRenderer.java:101)[optimized]

at javax/faces/component/UIComponentBase.encodeChildren(UIComponentBase.java:849)[optimized]

at com/sun/faces/renderkit/html_basic/HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:300)[inlined]

at com/sun/faces/renderkit/html_basic/GroupRenderer.encodeChildren(GroupRenderer.java:101)[optimized]

at javax/faces/component/UIComponentBase.encodeChildren(UIComponentBase.java:849)[optimized]

at javax/faces/component/UIComponent.encodeAll(UIComponent.java:1648)[optimized]

at javax/faces/render/Renderer.encodeChildren(Renderer.java:164)[optimized]

at javax/faces/component/UIComponentBase.encodeChildren(UIComponentBase.java:849)[optimized]

at javax/faces/component/UIComponent.encodeAll(UIComponent.java:1648)[optimized]

at javax/faces/component/UIComponent.encodeAll(UIComponent.java:1651)[optimized]

at javax/faces/component/UIComponent.encodeAll(UIComponent.java:1651)[optimized]

at com/sun/faces/application/view/FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:395)[optimized]

at com/sun/faces/application/view/MultiViewHandler.renderView(MultiViewHandler.java:127)[inlined]

at com/sun/faces/lifecycle/RenderResponsePhase.execute(RenderResponsePhase.java:117)[optimized]

at com/sun/faces/lifecycle/Phase.doPhase(Phase.java:97)[optimized]

at com/sun/faces/lifecycle/LifecycleImpl.render(LifecycleImpl.java:135)[optimized]

at javax/faces/webapp/FacesServlet.service(FacesServlet.java:309)[optimized]

at weblogic/servlet/internal/StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)[optimized]

at weblogic/servlet/internal/StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)[inlined]

at weblogic/servlet/internal/ServletStubImpl.execute(ServletStubImpl.java:300)[optimized]

at weblogic/servlet/internal/TailFilter.doFilter(TailFilter.java:26)[optimized]

at weblogic/servlet/internal/FilterChainImpl.doFilter(FilterChainImpl.java:56)[optimized]

at org/primefaces/webapp/filter/FileUploadFilter.doFilter(FileUploadFilter.java:79)[optimized]

at weblogic/servlet/internal/FilterChainImpl.doFilter(FilterChainImpl.java:56)[optimized]

at nl/sidn/web/support/em/EntityManagerFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V(Unknown Source)

at weblogic/servlet/internal/FilterChainImpl.doFilter(FilterChainImpl.java:56)[optimized]

at org/springframework/security/util/FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)[optimized]

at org/springframework/security/intercept/web/FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)[inlined]

at org/springframework/security/intercept/web/FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)[optimized]

at org/springframework/security/util/FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)[optimized]

at org/springframework/security/ui/ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)

at org/springframework/security/ui/SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)[optimized]

at org/springframework/security/util/FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)[optimized]

at org/springframework/security/providers/anonymous/AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)[optimized]

at org/springframework/security/ui/SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)[optimized]

at org/springframework/security/util/FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)[optimized]

at org/springframework/security/ui/logout/LogoutFilter.doFilterHttp(LogoutFilter.java:89)

at org/springframework/security/ui/SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)[optimized]

at org/springframework/security/util/FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)[optimized]

at org/springframework/security/ui/preauth/AbstractPreAuthenticatedProcessingFilter.doFilterHttp(AbstractPreAuthenticatedProcessingFilter.java:69)[optimized]

at org/springframework/security/ui/SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)[optimized]

at org/springframework/security/util/FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)[optimized]

at org/springframework/security/context/HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)[optimized]

at org/springframework/security/ui/SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)[optimized]

at org/springframework/security/util/FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)[optimized]

at org/springframework/security/util/FilterChainProxy.doFilter(FilterChainProxy.java:175)[optimized]

at org/springframework/web/filter/DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)[optimized]

at org/springframework/web/filter/DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)

at weblogic/servlet/internal/FilterChainImpl.doFilter(FilterChainImpl.java:56)[optimized]

at nl/sidn/web/security/xsrf/CSRFFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V(Unknown Source)[optimized]

at weblogic/servlet/internal/FilterChainImpl.doFilter(FilterChainImpl.java:56)[optimized]

at weblogic/servlet/internal/RequestEventsFilter.doFilter(RequestEventsFilter.java:27)[optimized]

at weblogic/servlet/internal/FilterChainImpl.doFilter(FilterChainImpl.java:56)[inlined]

at weblogic/servlet/internal/WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)[inlined]

at weblogic/servlet/internal/WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)[optimized]

at weblogic/security/acl/internal/AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)[optimized]

at weblogic/security/service/SecurityManager.runAs(SecurityManager.java:120)[inlined]

at weblogic/servlet/internal/WebAppServletContext.securedExecute(WebAppServletContext.java:2277)[inlined]

at weblogic/servlet/internal/WebAppServletContext.execute(WebAppServletContext.java:2183)[optimized]

at weblogic/servlet/internal/ServletRequestImpl.run(ServletRequestImpl.java:1454)[optimized]

at weblogic/work/ExecuteThread.execute(ExecuteThread.java:207)[optimized]

at weblogic/work/ExecuteThread.run(ExecuteThread.java:176)

at jrockit/vm/RNI.c2java(JJJJJ)V(Native Method)



 Comments   
Comment by Ed Burns [ 10/Oct/12 ]

When you say "if a user post multiple simultaneous requests to the bean" do you mean that there are multiple browser window/tabs in play here?

Comment by crcerror [ 10/Oct/12 ]

yes multiple tabs/windows or users who have created scripts which they use to send requests to the application and creating heavy load while doing so.

i am not sure if the above analysis is correct, the only thing a have is the thread dump. But it is a big problem for us because the code in UIComponent
freezes and never returns the running thread to the pool. This could bring down our server in severe cases.

Comment by Ed Burns [ 10/Oct/12 ]

As a workaround, and to aid in problem determination, can you change from using @ViewScoped to @SessionScoped, just for the problem bean? If that causes the problem to no longer manifest, then we have a starting point for understanding what's going on?

Comment by crcerror [ 19/Oct/12 ]

Hi Ed,

We found out what the problem was.
somehow we packaged two versions of jsf (2.0.4 and 2.0.6) with our EAR artifact.
When we removed version 2.0.4 the problem dissapeard.

you can close this issue now.

thanks for your help!

Comment by Manfred Riem [ 19/Oct/12 ]

Closing as per submitter

Generated at Fri May 22 11:34:16 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.