|
From: Juergen H. <ju...@in...> - 2005-01-29 19:12:41
|
OK... Nevertheless, it obviously happens in a lazy-initializing proxy
reference in a Hibernate-persisted object, which keeps its own Hibernate
Session internally rather than taking the current thread-bound one. Such an
object carries around its own Session even when accessed by some other
thread.
I bet that your application puts a persistent object somewhere where it can
get accessed by other threads, so those other threads implicitly access the
Session held in the persistent object through the Hibermate-generated CGLIB
proxy for loading. Maybe some code sticks a persistent object into an
instance variable of a Servlet, Controller or singleton service bean, which
are not thread-safe - but which will usually just cause actual issues in a
heavily-loaded scenario.
In total, I'm 99% sure that ThreadLocals and Spring's association of
Sessions with threads does *not* have anything to do with this. Try to find
out the expression in your Velocity template that causes the lazy-init
exception. It should be quite straightforward to track down where that
object came from.
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf Of
March, Andres
Sent: Saturday, January 29, 2005 7:55 PM
To: spr...@li...
Subject: RE: [Springframework-developer] Non Thread-safe hibernate session
Unfortunately, this is not the case here. We are using jmeter with
unauthenticated requests and therefore put nothing in the httpsession.
Additionally, your example should take place with as little as 2 requests:
one fetching the object and sticking it into the HttpSession, the other
trying to initialize its collections. In our case, we have to create a
decent amount of load (~30 pages/sec) for the errors to occur. Any other
ideas?
----------------------------------------------------------------------------
--
From: spr...@li...
[mailto:spr...@li...] On Behalf Of
Juergen Hoeller
Sent: Saturday, January 29, 2005 2:44 AM
To: spr...@li...
Subject: RE: [Springframework-developer] Non Thread-safe hibernate session
Actually, this can happen without either Spring or the ThreadLocal
mechanism breaking: One of your persistent objects might hold a lazy
persistent collection, which holds a reference to the Session that
originally loaded it.
If you put such a persistent object into the HttpSession, for example, the
original request that loaded the object (in thread TPProcessor1) will have
completed and thus the Hibernate Session have been closed. Now, if you take
your persistent object out of the HttpSession again in a new request (in
thread TPProcessor7) and try to access it lazy collection, it's gonna fail
because the original Session has been closed.
So the "leak" where a Session reference got out of its original
request/thread context is your persistent object in the HttpSession here.
This is a well-known problem: To make lazy loading work here, you need to
attach the persistent object to the new Hibernate Session (via lock or
saveOrUpdate).
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf Of
March, Andres
Sent: Friday, January 28, 2005 8:27 PM
To: spr...@li...
Subject: [Springframework-developer] Non Thread-safe hibernate session
As you can see below, a thread, other than the one that had the session
created for it, tries to access a session but it has been closed by the
valid owner thread. This only occurs under decent load. There must be some
thread safety issue in Spring or the whole ThreadLocal idea goes out the
window. Does anybody have any idea how this could occur? I don't see how I
could be misinterpreting this trace.
FATAL (SessionImpl.java:528) - Constructor for session:
net.sf.hibernate.impl.SessionImpl@b72884 on thread : TP-Processor1
FATAL (SessionFactoryImpl.java:342) - Session :
net.sf.hibernate.impl.SessionImpl@b72884 created for Thread : TP-Processor1
.later on.
closing session : net.sf.hibernate.impl.SessionImpl@b72884 and conn:
com.mchange.v2.c3p0.impl.NewProxyConnection@4ad009 on Thread : TP-Processor1
.later on.
net.sf.hibernate.HibernateException: Session is closed :
net.sf.hibernate.impl.SessionImpl@b72884 on thread : TP-Processor7
at
net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3313)
at
net.sf.hibernate.proxy.LazyInitializer.initialize(LazyInitializer.java:47)
at
net.sf.hibernate.proxy.LazyInitializer.initializeWrapExceptions(LazyInitiali
zer.java:60)
at
net.sf.hibernate.proxy.LazyInitializer.getImplementation(LazyInitializer.jav
a:164)
at
net.sf.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.j
ava:108)
at
com.sony.soe.guilds.model.GameCharacter$$EnhancerByCGLIB$$25b6cd13.getBioIma
ge(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.apache.velocity.runtime.parser.node.PropertyExecutor.execute(PropertyExe
cutor.java:111)
at
org.apache.velocity.util.introspection.UberspectImpl$VelGetterImpl.invoke(Ub
erspectImpl.java:300)
at
org.apache.velocity.runtime.parser.node.ASTIdentifier.execute(ASTIdentifier.
java:157)
at
org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.ja
va:175)
at
org.apache.velocity.runtime.parser.node.ASTReference.evaluate(ASTReference.j
ava:307)
at
org.apache.velocity.runtime.parser.node.ASTNotNode.evaluate(ASTNotNode.java:
47)
at
org.apache.velocity.runtime.parser.node.ASTExpression.evaluate(ASTExpression
.java:46)
at
org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement
.java:69)
at
org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:23
1)
at
org.apache.velocity.runtime.directive.Parse.render(Parse.java:181)
at
org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.jav
a:116)
at
org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:56)
at
org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement
.java:71)
at
org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:56)
at
org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement
.java:71)
at
org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:23
1)
at
org.apache.velocity.runtime.directive.Parse.render(Parse.java:181)
at
org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.jav
a:116)
at
org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:23
1)
at org.apache.velocity.Template.merge(Template.java:256)
at com.sony.soe.web.mvc.VelocityView.go(VelocityView.java:181)
at
com.sony.soe.guilds.view.VelocityLayout.go(VelocityLayout.java:135)
at
org.infohazard.maverick.flow.CommandBase.go(CommandBase.java:79)
at
org.infohazard.maverick.Dispatcher.service(Dispatcher.java:345)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:237)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:157)
at
net.sf.acegisecurity.ui.AbstractIntegrationFilter.doFilter(AbstractIntegrati
onFilter.java:170)
at
com.sony.soe.guilds.controller.SecurityFilter.doFilter(SecurityFilter.java:1
18)
at
net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:
88)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:186)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:157)
at
org.springframework.orm.hibernate.support.OpenSessionInViewFilter.doFilterIn
ternal(OpenSessionInViewFilter.java:17
1)
at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestF
ilter.java:76)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:186)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:157)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:214)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
t.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContext
Valve.java:198)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:152)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
t.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137
)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
t.java:104)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117
)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
t.java:102)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:109)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
t.java:104)
at
org.apache.catalina.valves.RequestDumperValve.invoke(RequestDumperValve.java
:169)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
t.java:102)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:296)
at
org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:372)
at
org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:694)
at
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:626)
at
org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:807)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:644)
at java.lang.Thread.run(Thread.java:534)
-----------------------------------------
Andres March
Platform - Apps Engineering
Sony Online Entertainment
desk: 858.577.3373
cell: 619.519.1519
|