yufish / memcached-session-manager

Automatically exported from code.google.com/p/memcached-session-manager
0 stars 0 forks source link

Problem with session handling #136

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, I'm currently trying to migrate from grails 1.3.7 to 2.0.1 and I'm having 
some problems with the session handling in the spring-webflow module in tomcat 
6.0.32.

I'm running my applications on two tomcats and one memcached vm, all of them 
running on ubuntu server 10.10.

The first request that comes into my application and is captures by tomcat1 is 
created successfuly with no exceptions raised. But when the subsequence request 
comes into tomcat2 the app is raising an "unread block data" Exception:

2012-05-15 14:47:46 [THREAD: http-8080-exec-3] ERROR 
[errors.GrailsExceptionResolver] IllegalStateException occurred when processing 
request: [GET] /orderNew/mlUser
unread block data. Stacktrace follows:
java.lang.IllegalStateException: unread block data
    at java.io.ObjectInputStream$BlockDataInputStream.setBlockDataMode(ObjectInputStream.java:2376)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1360)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
    at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:479)
    at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1791)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    at java.util.LinkedList.readObject(LinkedList.java:964)
    at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1791)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    at grails.plugin.springcache.web.GrailsFragmentCachingFilter.doFilter(GrailsFragmentCachingFilter.groovy:66)
    at net.sf.ehcache.constructs.web.filter.Filter.doFilter(Filter.java:86)
    at de.javakaffee.web.msm.SessionTrackerValve.invoke(SessionTrackerValve.java:126)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

Also, the memcached log for this two executions is:

<31 set D7DDCBE3FF4816909FBD38DC83AECEEB 2048 7200 7860
>31 STORED
<31 set validity:D7DDCBE3FF4816909FBD38DC83AECEEB 2048 3600 20
>31 STORED
<30 get D7DDCBE3FF4816909FBD38DC83AECEEB
>30 sending key D7DDCBE3FF4816909FBD38DC83AECEEB
>30 END
<30 get validity:D7DDCBE3FF4816909FBD38DC83AECEEB
>30 sending key validity:D7DDCBE3FF4816909FBD38DC83AECEEB- 2048 20

>30 END
<30 set validity:D7DDCBE3FF4816909FBD38DC83AECEEB 2048 3600 20
>30 STORED
<30 add D7DDCBE3FF4816909FBD38DC83AECEEB 512 5 1
>30 NOT_STORED

The configuration i'm using is context.xml is:

    <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
            memcachedNodes="n1:172.16.143.116:11211"
            sessionBackupAsync="false"
            sessionBackupTimeout="1000"
            operationTimeout="10000"
            sticky="false" 
            lockingMode="auto"
            requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
            transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
     />

(I've tried a lot of the configurations, that's because the timeouts and that, 
but before the migration to grails 2.0.1 it was running with the standard 
recommended in this forum with two nodes and no failover).

Can you please give me a tip on what the problem is? Thanks a lot!

Perhaps you can try this with a smaller project 
(https://github.com/houbie/livesnippets). I can send you mine, but it has a lot 
of proper configurations of ths internal restAPI and it wont work.

Trygve.

Original issue reported on code.google.com by trygve...@gmail.com on 21 May 2012 at 2:44

GoogleCodeExporter commented 9 years ago
On the grails mailing list I found a user that reported this issue related to a 
serialized HibernateSession. Not sure which object is causing the problem in 
your case, but you might try to add

customConverter="de.javakaffee.web.msm.serializer.kryo.HibernateCollectionsSeria
lizerFactory"

to your msm config and see if this helps. Otherwise you'd have to find out 
which object is causing the serialization issue (which is not caused directly 
by msm) and then changing the serialization for this object/class (I can help 
with that).

Currently my time is very limited, so unfortunately I can't help much with the 
analysis.

Cheers,
Martin

Original comment by martin.grotzke on 22 May 2012 at 9:07

GoogleCodeExporter commented 9 years ago
Hi Martin, 

I tried what you recommended and it didn't work, it now fails in every request 
without bothering which tomcat created the session :-(.

I will still be looking for the answer and any clue you can give me will be 
very appreciated! (We're king of stuck on this for a couple of days now).

Thank you very much for your help.

Regards,

Trygve.

Original comment by trygve...@gmail.com on 22 May 2012 at 11:12

GoogleCodeExporter commented 9 years ago
It seems to be an issue with GrailsFragmentCachingFilter. How does it work when 
you disable the springcache plugin? How does the GrailsFragmentCachingFilter / 
where does it keep the cached items (via ehcache, in memory / on disk)?

How does GrailsFragmentCachingFilter work if you're not using msm?

Original comment by martin.grotzke on 22 May 2012 at 12:02

GoogleCodeExporter commented 9 years ago
Martin, By the moment I posted the second reply I've already unninstalled the 
grails spŕing cache that contains the GrailsFragmentCachingFilter, so the new 
stacktrace remains the same (excluding the previously mentioned class).

I've found the extended and more informative stacktrace:

2012-05-22 06:41:25,749 [http-8080-exec-1] ERROR StackTrace  - Full Stack Trace:
java.lang.IllegalStateException: unread block data
    at java.io.ObjectInputStream$BlockDataInputStream.setBlockDataMode(ObjectInputStream.java:2376)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1360)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
    at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:479)
    at org.springframework.webflow.core.collection.LocalAttributeMap.readObject(LocalAttributeMap.java:331)
    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:597)
    at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    at org.springframework.webflow.engine.impl.FlowSessionImpl.readExternal(FlowSessionImpl.java:147)
    at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1791)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    at java.util.LinkedList.readObject(LinkedList.java:964)
    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:597)
    at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    at org.springframework.webflow.engine.impl.FlowExecutionImpl.readExternal(FlowExecutionImpl.java:305)
    at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1791)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    at org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshot.deserialize(SerializedFlowExecutionSnapshot.java:193)
    at org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshot.unmarshal(SerializedFlowExecutionSnapshot.java:98)
    at org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshotFactory.restoreExecution(SerializedFlowExecutionSnapshotFactory.java:80)
    at org.springframework.webflow.execution.repository.snapshot.AbstractSnapshottingFlowExecutionRepository.restoreFlowExecution(AbstractSnapshottingFlowExecutionRepository.java:89)
    at org.springframework.webflow.execution.repository.impl.DefaultFlowExecutionRepository.getFlowExecution(DefaultFlowExecutionRepository.java:112)
    at org.codehaus.groovy.grails.webflow.execution.GrailsFlowExecutorImpl.resumeExecution(GrailsFlowExecutorImpl.java:65)
    at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183)
    at org.codehaus.groovy.grails.webflow.mvc.servlet.GrailsFlowHandlerAdapter.handle(GrailsFlowHandlerAdapter.java:54)
    at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:325)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:70)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:70)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:70)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
    at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:311)
    at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:276)
    at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:267)
    at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:209)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.obtainContent(GrailsPageFilter.java:200)
    at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.doFilter(GrailsPageFilter.java:151)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:69)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:69)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at de.javakaffee.web.msm.SessionTrackerValve.invoke(SessionTrackerValve.java:126)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:554)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:889)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:732)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:2262)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

I've read in another post that perhaps the problem comes into the Hibernate 
sessionFactoryName. I'm trying to figure out where to configure that, but in 
the short-term thinking i'm not seeing the relationship with the tomcat 
sessions module.

Thanks for all your help, I owe you a beer, so if you pass by Argentina some 
time, let me know!

Regards,

Trygve.

Original comment by trygve...@gmail.com on 22 May 2012 at 1:44

GoogleCodeExporter commented 9 years ago
Hi Trygve, allright, it would be nice if you'd drop a note here once you solved 
it (now I'm curious :-)), and let's see if I'll be in argentina sometimes :-)

Cheers,
Martin

Original comment by martin.grotzke on 22 May 2012 at 2:59

GoogleCodeExporter commented 9 years ago
Hi Martin, we've come to a solution of this, the problem was with the hibernate 
sessionFactory. The workaround for this was to include the 
grails-app/conf/hibernate /hibernate.cfg.xml and set the sessionFactory Name.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
'-//Hibernate/Hibernate Configuration DTD 3.0//EN'
'http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd'>

<hibernate-configuration>

<session-factory name="definedForAvoidBoooom">
<!--
<mapping package='com.books' />

<mapping class='com.books.Book' />

<mapping resource='someresource.hbm.xml'/>
-->
</session-factory>

</hibernate-configuration>

Thanks a lot for your help.

Regards, 

Trygve.

Original comment by trygve...@gmail.com on 13 Jun 2012 at 2:35

GoogleCodeExporter commented 9 years ago
Great!

Original comment by martin.grotzke on 13 Jun 2012 at 1:54