Details
-
Bug
-
Status: Closed
-
Blocker
-
Resolution: Fixed
-
2.2
-
None
-
Patch available
-
Components: Sitemap - 1.0.0-RC3-dev
-
Components: Sitemap - 1.0.0-RC3-dev
Description
There is a serious bug in o.a.c.core.container.spring.avalon.PoolableProxyHandler (and PoolableFactoryBean) that can lead to exceptions like "Cannot set reader. Generator already set". This is because the pipeline impl bean is reused from the pool, but was never recycle()d. The recycle() call is skipped in cases when an exception is thrown by Spring inside PoolableProxyHandler.invoke("putBackIntoAvalonPool") - this exception is simply swalled by both PoolableProxyHandler.run() and PoolableFactoryBean.putIntoPool().
The typical behaviour is that the first call to the pipeline works, but because the components are put back into the pool unrecycled, the next call will fail. If there is lots of activity, you might get a fresh component from the pool and it might work again, so the error seems quite random.
The problematic exception happens when RequestContextHolder.currentRequestAttributes() is called when the attributes for the request are null: IllegalStateException("No thread-bound request found:....."). The call to that method happens in the "putBackIntoAvalonPool" case in PoolableProxyHandler.invoke(). The problem is that this code will also be called *after* the request attributes were set to null by the RequestContextListener, because it is registered as a destruction callback, that gets called by Spring after the attribute reset.
The real chain of calls is as follows:
RequestContextListener.requestDestroyed()
RequestContextHolder.setRequestAttributes(null)
callDestructionCallbacks()
PoolableProxyHandler.run() <- which is a destruction callback
PoolableFactoryBean.putIntoPool()
PoolableFactoryBean.enteringPool()
component.recycle()
AvalonServiceManager/Selector.release(childComponent) <- component releases its childComponent
AvalonPoolable.putBackIntoAvalonPool()
PoolableProxyHandler.invoke() <- intercepts the putBackIntoAvalonPool() call
RequestContextHolder.currentRequestAttributes() <-- Exception !!!
The typical behaviour is that the first call to the pipeline works, but because the components are put back into the pool unrecycled, the next call will fail. If there is lots of activity, you might get a fresh component from the pool and it might work again, so the error seems quite random.
The problematic exception happens when RequestContextHolder.currentRequestAttributes() is called when the attributes for the request are null: IllegalStateException("No thread-bound request found:....."). The call to that method happens in the "putBackIntoAvalonPool" case in PoolableProxyHandler.invoke(). The problem is that this code will also be called *after* the request attributes were set to null by the RequestContextListener, because it is registered as a destruction callback, that gets called by Spring after the attribute reset.
The real chain of calls is as follows:
RequestContextListener.requestDestroyed()
RequestContextHolder.setRequestAttributes(null)
callDestructionCallbacks()
PoolableProxyHandler.run() <- which is a destruction callback
PoolableFactoryBean.putIntoPool()
PoolableFactoryBean.enteringPool()
component.recycle()
AvalonServiceManager/Selector.release(childComponent) <- component releases its childComponent
AvalonPoolable.putBackIntoAvalonPool()
PoolableProxyHandler.invoke() <- intercepts the putBackIntoAvalonPool() call
RequestContextHolder.currentRequestAttributes() <-- Exception !!!