Just coming up with ideas here: what if the listeners being iterated through in org.apache.catalina.core.StandardContext.fireRequestDestroyEvent are the issue? If the facesContext/request/session is torn down before the owb listener OWB gets a chance to clean up the beans it could be causing a problem? If the order of the iteration is not stable that could also explain why the issue is intermittent.
There is actually a note about this in the MyFaces source (org.apache.myfaces.cdi.view.ViewScopeBeanHolder.destroyBeansOnPreDestroy) where they are dealing with differences between CDI implementations and mention Tomcat + OWB. On Wed, Nov 16, 2016 at 12:09 PM, Adam Cornett <[email protected]> wrote: > Wouldn't that be easy :) > > I have not been able to reproduce this in a simple test case. After some > more testing on our app I have found that the first stack trace I posted is > actually generated when trying to render our custom error page. When I > take the custom error page out the second error in OP (posted again below) > is the exception causing the problem. > > > org.apache.webbeans.component.ManagedBean - Exception thrown while > destroying bean instance : [ViewScopeBeanHolder, WebBeansType:MANAGED, > Name:null, API Types:[java.io.Serializable,java.lang.Object,org.apache. > myfaces.cdi.view.ViewScopeBeanHolder], Qualifiers:[javax.enterprise. > inject.Default,javax.enterprise.inject.Any]] > java.lang.NullPointerException: null > at org.apache.myfaces.cdi.view.ViewScopeContextImpl.destroyAllActive( > ViewScopeContextImpl.java:229) > at org.apache.myfaces.cdi.view.ViewScopeContextImpl.destroyAllActive( > ViewScopeContextImpl.java:223) > at org.apache.myfaces.cdi.view.ViewScopeBeanHolder. > destroyBeansOnPreDestroy(ViewScopeBeanHolder.java:221) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke( > NativeMethodAccessorImpl.java:62) > at sun.reflect.DelegatingMethodAccessorImpl.invoke( > DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:498) > at org.apache.webbeans.intercept.LifecycleInterceptorInvocation > Context.proceed(LifecycleInterceptorInvocationContext.java:103) > at org.apache.webbeans.portable.InjectionTargetImpl.preDestroy( > InjectionTargetImpl.java:352) > at org.apache.webbeans.component.AbstractOwbBean.destroy( > AbstractOwbBean.java:179) > at org.apache.webbeans.context.AbstractContext.destroyInstance( > AbstractContext.java:206) > at org.apache.webbeans.context.AbstractContext.destroyInstance( > AbstractContext.java:192) > at org.apache.webbeans.context.AbstractContext.destroy( > AbstractContext.java:218) > at org.apache.webbeans.web.context.WebContextsService. > destroyRequestContext(WebContextsService.java:408) > at org.apache.openejb.cdi.CdiAppContextsService.destroyRequestContext( > CdiAppContextsService.java:113) > at org.apache.webbeans.web.context.WebContextsService. > endContext(WebContextsService.java:223) > at org.apache.openejb.server.httpd.BeginWebBeansListener.requestDestroyed( > BeginWebBeansListener.java:99) > at org.apache.catalina.core.StandardContext.fireRequestDestroyEvent( > StandardContext.java:5965) > at org.apache.catalina.core.StandardHostValve.invoke( > StandardHostValve.java:182) > at org.apache.catalina.valves.ErrorReportValve.invoke( > ErrorReportValve.java:79) > at org.apache.tomee.catalina.OpenEJBSecurityListener$ > RequestCapturer.invoke(OpenEJBSecurityListener.java:97) > at org.apache.catalina.core.StandardEngineValve.invoke( > StandardEngineValve.java:87) > at org.apache.catalina.connector.CoyoteAdapter.service( > CoyoteAdapter.java:349) > at org.apache.coyote.http11.Http11Processor.service( > Http11Processor.java:784) > at org.apache.coyote.AbstractProcessorLight.process( > AbstractProcessorLight.java:66) > at org.apache.coyote.AbstractProtocol$ConnectionHandler.process( > AbstractProtocol.java:802) > at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor. > doRun(NioEndpoint.java:1410) > at org.apache.tomcat.util.net.SocketProcessorBase.run( > SocketProcessorBase.java:49) > at java.util.concurrent.ThreadPoolExecutor.runWorker( > ThreadPoolExecutor.java:1142) > at java.util.concurrent.ThreadPoolExecutor$Worker.run( > ThreadPoolExecutor.java:617) > at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run( > TaskThread.java:61) > at java.lang.Thread.run(Thread.java:745) > > Looking an the MyFaces code it looks like the there is no active faces > instance (FacesContext.getCurrentInstance()) when it tries to destroy the > beans. > > > On Wed, Nov 16, 2016 at 10:51 AM, Romain Manni-Bucau < > [email protected]> wrote: > >> 2016-11-16 16:48 GMT+01:00 Adam Cornett <[email protected]>: >> >> > I don't think so. This error will happen for even the simplest bean: we >> > have one 40 line class that just loads a list of JPA objects from the db >> > and sorts it for presentation and it triggers the issue too. So far I >> have >> > seen this happen on at least 8 different view scoped beans across >> different >> > wars in our product. >> > >> > >> Does that mean it is easy to reproduce on a github project? 0:-) >> >> >> > I've been trying to sort this out for two days now and can't figure out >> if >> > it is caused by a change in our app or if there is something going on in >> > OWB/MyFaces/TomEE. I've disabled tomcat session replication and the >> issue >> > still persists (although sometimes it takes many tries to get the issue >> to >> > manifest). >> > >> > We have session beans all over our application and those work fine, it >> is >> > just he viewscoped ones that can trigger the issue. The intermittent >> > nature of the problem is also very confusing. What sort of things >> could I >> > do in our application code that would cause the container to loose the >> > request? >> > >> > >> > On Wed, Nov 16, 2016 at 10:35 AM, Romain Manni-Bucau < >> > [email protected]> >> > wrote: >> > >> > > Normally the session is captured from the request. Is it possible you >> > loose >> > > the request when touching this bean somehow? >> > > >> > > >> > > Romain Manni-Bucau >> > > @rmannibucau <https://twitter.com/rmannibucau> | Blog >> > > <https://blog-rmannibucau.rhcloud.com> | Old Blog >> > > <http://rmannibucau.wordpress.com> | Github <https://github.com/ >> > > rmannibucau> | >> > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory >> > > <https://javaeefactory-rmannibucau.rhcloud.com> >> > > >> > > 2016-11-16 15:51 GMT+01:00 Adam Cornett <[email protected]>: >> > > >> > > > Using TomEE 7.0.2 we are seeing intermittent problems with beans >> > > > using javax.faces.view.ViewScoped. >> > > > We have many pages that use @ViewScoped beans, but the behavior of >> this >> > > > issue is not predictable. Sometimes we can login and not have any >> > issue >> > > at >> > > > all, sometimes it will only impact a single bean and all other >> > > @ViewScoped >> > > > beans will work fine, but when a bean starts throwing an error, it >> will >> > > > keep throwing the error until the user logs out (ends the servlet >> > > session) >> > > > and then when logging back it in may or may not happen again. >> > > > >> > > > >> > > > The primary error is below: >> > > > javax.enterprise.context.ContextNotActiveException: WebBeans >> context >> > > with >> > > > scope type annotation @SessionScoped does not exist within current >> > thread >> > > > at >> > > > org.apache.webbeans.container.BeanManagerImpl.getContext( >> > > > BeanManagerImpl.java:331) >> > > > at >> > > > org.apache.webbeans.intercept.NormalScopedBeanInterceptorHan >> > > > dler.getContextualInstance(NormalScopedBeanInterceptorHandle >> r.java:89) >> > > > at >> > > > org.apache.webbeans.intercept.SessionScopedBeanInterceptorHa >> > > > ndler.getContextualInstance(SessionScopedBeanInterceptorHa >> > ndler.java:76) >> > > > at >> > > > org.apache.webbeans.intercept.NormalScopedBeanInterceptorHan >> dler.get( >> > > > NormalScopedBeanInterceptorHandler.java:71) >> > > > at >> > > > org.apache.myfaces.cdi.view.ViewScopeBeanHolder$$OwbNormalSc >> opeProxy0. >> > > > generateUniqueViewScopeId(org/apache/myfaces/cdi/view/ >> > > > ViewScopeBeanHolder.java) >> > > > at >> > > > org.apache.myfaces.cdi.impl.CDIManagedBeanHandlerImpl. >> > > generateViewScopeId( >> > > > CDIManagedBeanHandlerImpl.java:92) >> > > > at >> > > > org.apache.myfaces.view.ViewScopeProxyMap.getWrapped( >> > > > ViewScopeProxyMap.java:79) >> > > > at org.apache.myfaces.view.ViewScopeProxyMap.size( >> > > > ViewScopeProxyMap.java:99) >> > > > at javax.faces.component.UIViewRoot.saveState(UIViewRoot.java:1502) >> > > > at >> > > > org.apache.myfaces.renderkit.ErrorPageWriter._writeComponent( >> > > > ErrorPageWriter.java:851) >> > > > at >> > > > org.apache.myfaces.renderkit.ErrorPageWriter.debugHtml( >> > > > ErrorPageWriter.java:352) >> > > > at >> > > > org.apache.myfaces.renderkit.ErrorPageWriter.handle( >> > > > ErrorPageWriter.java:471) >> > > > at >> > > > org.apache.myfaces.context.MyFacesExceptionHandlerWrapperImp >> l.handle( >> > > > MyFacesExceptionHandlerWrapperImpl.java:301) >> > > > at >> > > > javax.faces.context.ExceptionHandlerWrapper.handle( >> > > > ExceptionHandlerWrapper.java:61) >> > > > at >> > > > org.apache.webbeans.jsf.OwbExceptionHandler.handle( >> > > > OwbExceptionHandler.java:61) >> > > > at org.apache.myfaces.lifecycle.LifecycleImpl.render( >> > > > LifecycleImpl.java:287) >> > > > at javax.faces.webapp.FacesServlet.service(FacesServlet.java:200) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( >> > > > ApplicationFilterChain.java:230) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.doFilter( >> > > > ApplicationFilterChain.java:165) >> > > > at org.apache.tomcat.websocket.server.WsFilter.doFilter( >> > > WsFilter.java:52) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( >> > > > ApplicationFilterChain.java:192) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.doFilter( >> > > > ApplicationFilterChain.java:165) >> > > > at >> > > > org.apache.catalina.core.ApplicationDispatcher.invoke( >> > > > ApplicationDispatcher.java:726) >> > > > at >> > > > org.apache.catalina.core.ApplicationDispatcher.processRequest( >> > > > ApplicationDispatcher.java:469) >> > > > at >> > > > org.apache.catalina.core.ApplicationDispatcher.doForward( >> > > > ApplicationDispatcher.java:394) >> > > > at >> > > > org.apache.catalina.core.ApplicationDispatcher.forward( >> > > > ApplicationDispatcher.java:311) >> > > > at >> > > > com.achalert.alert.security.servlets.LoginHandlerServlet. >> > processRequest( >> > > > LoginHandlerServlet.java:186) >> > > > at >> > > > com.achalert.alert.security.servlets.LoginHandlerServlet. >> > > > doPost(LoginHandlerServlet.java:371) >> > > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) >> > > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( >> > > > ApplicationFilterChain.java:230) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.doFilter( >> > > > ApplicationFilterChain.java:165) >> > > > at org.apache.tomcat.websocket.server.WsFilter.doFilter( >> > > WsFilter.java:52) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( >> > > > ApplicationFilterChain.java:192) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.doFilter( >> > > > ApplicationFilterChain.java:165) >> > > > at org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter. >> java:65) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( >> > > > ApplicationFilterChain.java:192) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.doFilter( >> > > > ApplicationFilterChain.java:165) >> > > > at >> > > > com.achalert.alert.security.filters.SessionValidationFilter. >> doFilter( >> > > > SessionValidationFilter.java:134) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( >> > > > ApplicationFilterChain.java:192) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.doFilter( >> > > > ApplicationFilterChain.java:165) >> > > > at >> > > > com.achalert.alert.http.OmnibusAchAlertFilter.doFilter( >> > > > OmnibusAchAlertFilter.java:161) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( >> > > > ApplicationFilterChain.java:192) >> > > > at >> > > > org.apache.catalina.core.ApplicationFilterChain.doFilter( >> > > > ApplicationFilterChain.java:165) >> > > > at >> > > > org.apache.catalina.core.StandardWrapperValve.invoke( >> > > > StandardWrapperValve.java:198) >> > > > at >> > > > org.apache.catalina.core.StandardContextValve.invoke( >> > > > StandardContextValve.java:108) >> > > > at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve. >> java:44) >> > > > at >> > > > org.apache.catalina.authenticator.AuthenticatorBase.invoke( >> > > > AuthenticatorBase.java:472) >> > > > at >> > > > org.apache.catalina.core.StandardHostValve.invoke( >> > > > StandardHostValve.java:140) >> > > > at >> > > > org.apache.catalina.valves.ErrorReportValve.invoke( >> > > > ErrorReportValve.java:79) >> > > > at >> > > > org.apache.tomee.catalina.OpenEJBSecurityListener$ >> > > RequestCapturer.invoke( >> > > > OpenEJBSecurityListener.java:97) >> > > > at >> > > > org.apache.catalina.core.StandardEngineValve.invoke( >> > > > StandardEngineValve.java:87) >> > > > at >> > > > org.apache.catalina.connector.CoyoteAdapter.service( >> > > > CoyoteAdapter.java:349) >> > > > at >> > > > org.apache.coyote.http11.Http11Processor.service( >> > > Http11Processor.java:784) >> > > > at >> > > > org.apache.coyote.AbstractProcessorLight.process( >> > > > AbstractProcessorLight.java:66) >> > > > at >> > > > org.apache.coyote.AbstractProtocol$ConnectionHandler.process( >> > > > AbstractProtocol.java:802) >> > > > at >> > > > org.apache.tomcat.util.net.NioEndpoint$SocketProcessor. >> > > > doRun(NioEndpoint.java:1410) >> > > > at >> > > > org.apache.tomcat.util.net.SocketProcessorBase.run( >> > > > SocketProcessorBase.java:49) >> > > > at >> > > > java.util.concurrent.ThreadPoolExecutor.runWorker( >> > > > ThreadPoolExecutor.java:1142) >> > > > at >> > > > java.util.concurrent.ThreadPoolExecutor$Worker.run( >> > > > ThreadPoolExecutor.java:617) >> > > > at >> > > > org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run( >> > > > TaskThread.java:61) >> > > > at java.lang.Thread.run(Thread.java:745) >> > > > >> > > > I've also noticed that there is another error which may be related. >> > This >> > > > one is usually somewhere in the logs before the above error happens: >> > > > org.apache.webbeans.component.ManagedBean - Exception thrown while >> > > > destroying bean instance : [ViewScopeBeanHolder, >> WebBeansType:MANAGED, >> > > > Name:null, API >> > > > Types:[org.apache.myfaces.cdi.view.ViewScopeBeanHolder,java. >> > > > io.Serializable,java.lang.Object], >> > > > Qualifiers:[javax.enterprise.inject.Default,javax. >> > > enterprise.inject.Any]] >> > > > java.lang.NullPointerException: null >> > > > at >> > > > org.apache.myfaces.cdi.view.ViewScopeContextImpl.destroyAllActive( >> > > > ViewScopeContextImpl.java:229) >> > > > at >> > > > org.apache.myfaces.cdi.view.ViewScopeContextImpl.destroyAllActive( >> > > > ViewScopeContextImpl.java:223) >> > > > at >> > > > org.apache.myfaces.cdi.view.ViewScopeBeanHolder. >> > > destroyBeansOnPreDestroy( >> > > > ViewScopeBeanHolder.java:221) >> > > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> > > > at >> > > > sun.reflect.NativeMethodAccessorImpl.invoke( >> > > NativeMethodAccessorImpl.java: >> > > > 62) >> > > > at >> > > > sun.reflect.DelegatingMethodAccessorImpl.invoke( >> > > > DelegatingMethodAccessorImpl.java:43) >> > > > at java.lang.reflect.Method.invoke(Method.java:498) >> > > > at >> > > > org.apache.webbeans.intercept.LifecycleInterceptorInvocation >> > > > Context.proceed(LifecycleInterceptorInvocationContext.java:103) >> > > > at >> > > > org.apache.webbeans.portable.InjectionTargetImpl.preDestroy( >> > > > InjectionTargetImpl.java:352) >> > > > at >> > > > org.apache.webbeans.component.AbstractOwbBean.destroy( >> > > > AbstractOwbBean.java:179) >> > > > at >> > > > org.apache.webbeans.context.AbstractContext.destroyInstance( >> > > > AbstractContext.java:206) >> > > > at >> > > > org.apache.webbeans.context.AbstractContext.destroyInstance( >> > > > AbstractContext.java:192) >> > > > at >> > > > org.apache.webbeans.context.AbstractContext.destroy( >> > > > AbstractContext.java:218) >> > > > at >> > > > org.apache.webbeans.web.context.WebContextsService. >> > > destroyRequestContext( >> > > > WebContextsService.java:408) >> > > > at >> > > > org.apache.openejb.cdi.CdiAppContextsService.destroyRequestContext( >> > > > CdiAppContextsService.java:113) >> > > > at >> > > > org.apache.webbeans.web.context.WebContextsService. >> > > > endContext(WebContextsService.java:223) >> > > > at >> > > > org.apache.openejb.server.httpd.BeginWebBeansListener. >> > requestDestroyed( >> > > > BeginWebBeansListener.java:99) >> > > > at >> > > > org.apache.catalina.core.StandardContext.fireRequestDestroyEvent( >> > > > StandardContext.java:5965) >> > > > at >> > > > org.apache.catalina.core.StandardHostValve.invoke( >> > > > StandardHostValve.java:182) >> > > > at >> > > > org.apache.catalina.valves.ErrorReportValve.invoke( >> > > > ErrorReportValve.java:79) >> > > > at >> > > > org.apache.tomee.catalina.OpenEJBSecurityListener$ >> > > RequestCapturer.invoke( >> > > > OpenEJBSecurityListener.java:97) >> > > > at >> > > > org.apache.catalina.core.StandardEngineValve.invoke( >> > > > StandardEngineValve.java:87) >> > > > at >> > > > org.apache.catalina.connector.CoyoteAdapter.service( >> > > > CoyoteAdapter.java:349) >> > > > at >> > > > org.apache.coyote.http11.Http11Processor.service( >> > > Http11Processor.java:784) >> > > > at >> > > > org.apache.coyote.AbstractProcessorLight.process( >> > > > AbstractProcessorLight.java:66) >> > > > at >> > > > org.apache.coyote.AbstractProtocol$ConnectionHandler.process( >> > > > AbstractProtocol.java:802) >> > > > at >> > > > org.apache.tomcat.util.net.NioEndpoint$SocketProcessor. >> > > > doRun(NioEndpoint.java:1410) >> > > > at >> > > > org.apache.tomcat.util.net.SocketProcessorBase.run( >> > > > SocketProcessorBase.java:49) >> > > > at >> > > > java.util.concurrent.ThreadPoolExecutor.runWorker( >> > > > ThreadPoolExecutor.java:1142) >> > > > at >> > > > java.util.concurrent.ThreadPoolExecutor$Worker.run( >> > > > ThreadPoolExecutor.java:617) >> > > > at >> > > > org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run( >> > > > TaskThread.java:61) >> > > > at java.lang.Thread.run(Thread.java:745) >> > > > >> > > > >> > > > >> > > > Adam Cornett >> > > > >> > > >> > >> > >> > >> > -- >> > Adam Cornett >> > [email protected] >> > (678) 296-1150 >> > >> > > > > -- > Adam Cornett > [email protected] > (678) 296-1150 > -- Adam Cornett [email protected] (678) 296-1150
