Re: memcached-session-manager

139 views
Skip to first unread message

Martin Grotzke

unread,
Aug 28, 2013, 11:34:35 AM8/28/13
to Netanel Weinberg, memcached-session-manager
Hi Netanel,

please use the mailing list
(https://groups.google.com/forum/#!forum/memcached-session-manager) for
discussion/questions.

AFAICS your question is related to
http://code.google.com/p/memcached-session-manager/issues/detail?id=145.
The workaround I described in this issue has not yet found its way into
kryo-serializers, so you could contribute it :-)

Do you still have questions regarding the custom serializer for the
spring User class?

Cheers,
Martin





On 08/28/2013 03:15 PM, Netanel Weinberg wrote:
> Hi,
>
> I've seen there was a question in the project but haven't seen if it has
> been answered somewhere else.
> The question was:
> WARNING: Could not load session with id 64BBB510825CB8431BE50E7DB3C4320A
> from memcached.
> com.esotericsoftware.kryo.SerializationException: Unable to deserialize
> object of type: java.util.concurrent.ConcurrentHashMap
> at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:593)
> at
> com.esotericsoftware.kryo.ObjectBuffer.readObject(ObjectBuffer.java:213)
> at
> de.javakaffee.web.msm.serializer.kryo.KryoTranscoder.deserializeAttributes(KryoTranscoder.java:261)
> at
> de.javakaffee.web.msm.TranscoderService.deserializeAttributes(TranscoderService.java:169)
> at
> de.javakaffee.web.msm.TranscoderService.deserialize(TranscoderService.java:126)
> at
> de.javakaffee.web.msm.MemcachedSessionService.loadFromMemcached(MemcachedSessionService.java:1136)
> at
> de.javakaffee.web.msm.MemcachedSessionService.findSession(MemcachedSessionService.java:609)
> at
> de.javakaffee.web.msm.MemcachedBackupSessionManager.findSession(MemcachedBackupSessionManager.java:196)
> at org.apache.catalina.connector.Request.doGetSession(Request.java:2706)
> at org.apache.catalina.connector.Request.getSession(Request.java:2235)
> at
> org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:899)
> at
> javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:229)
> at
> org.springframework.security.web.context.HttpSessionSecurityContextRepository.loadContext(HttpSessionSecurityContextRepository.java:79)
> at
> org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:82)
> at
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
> at
> org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
> at
> org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
> 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:243)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
> at
> de.javakaffee.web.msm.RequestTrackingContextValve.invoke(RequestTrackingContextValve.java:99)
> at
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
> at
> de.javakaffee.web.msm.RequestTrackingHostValve.invoke(RequestTrackingHostValve.java:138)
> at
> de.javakaffee.web.msm.RequestTrackingHostValve.invoke(RequestTrackingHostValve.java:138)
> at
> de.javakaffee.web.msm.RequestTrackingHostValve.invoke(RequestTrackingHostValve.java:170)
> at
> de.javakaffee.web.msm.RequestTrackingHostValve.invoke(RequestTrackingHostValve.java:138)
> at
> de.javakaffee.web.msm.RequestTrackingHostValve.invoke(RequestTrackingHostValve.java:138)
> at
> de.javakaffee.web.msm.RequestTrackingHostValve.invoke(RequestTrackingHostValve.java:170)
> at
> de.javakaffee.web.msm.RequestTrackingHostValve.invoke(RequestTrackingHostValve.java:138)
> at
> de.javakaffee.web.msm.RequestTrackingHostValve.invoke(RequestTrackingHostValve.java:138)
> at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
> at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
> at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
> at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
> at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
> at
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:722)
> Caused by: com.esotericsoftware.kryo.SerializationException: Unable to
> deserialize object of type:
> org.springframework.security.core.context.SecurityContextImpl
> at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:571)
> at
> com.esotericsoftware.kryo.serialize.MapSerializer.readObjectData(MapSerializer.java:129)
> at com.esotericsoftware.kryo.Serializer.readObject(Serializer.java:61)
> at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:589)
> ... 43 more
> Caused by: com.esotericsoftware.kryo.SerializationException:
> Serialization trace:
> Caused by: java.lang.ClassCastException:
> org.springframework.security.core.authority.SimpleGrantedAuthority
> cannot be cast to java.lang.Comparable
> at java.util.TreeMap.compare(TreeMap.java:1188)
> at java.util.TreeMap.put(TreeMap.java:531)
> at java.util.TreeSet.add(TreeSet.java:255)
> at
> com.esotericsoftware.kryo.serialize.CollectionSerializer.readObjectData(CollectionSerializer.java:113)
> at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:566)
> at
> de.javakaffee.kryoserializers.UnmodifiableCollectionsSerializer.readObjectData(UnmodifiableCollectionsSerializer.java:84)
> at
> com.esotericsoftware.kryo.serialize.FieldSerializer.readObjectData(FieldSerializer.java:220)
> ... 52 more
>
> Is there any known solution for it?
>
> Thanks alot,
> Netanel

--
inoio gmbh - http://inoio.de
Schulterblatt 36, 20357 Hamburg
Amtsgericht Hamburg, HRB 123031
Geschäftsführer: Dennis Brakhane, Martin Grotzke, Ole Langbehn

signature.asc

Martin Grotzke

unread,
Aug 28, 2013, 3:58:36 PM8/28/13
to Netanel Weinberg, memcached-session-manager
Hi Netanel,

great it's working for you. I'll try to explain the issue and I hacked
a custom serializer that you could try with msm + kryo.

So why fails the deserialization of the spring security user object?
The User class internally contains a collection of GrantedAuthority,
which is actually a TreeSet with a Comparator (check the implementation
for this, see e.g. [1]). During deserialization kryo creates a new
TreeSet *without* any comparator and therefore expects that the
contained items are Comparable, which is not the case for
SimpleGrantedAuthority -> ClassCastException.

You find the custom serializer I wrote at
https://gist.github.com/magro/6370466.
You can configure msm to use it via the customConverter attribute:

...
customConverter="de.javakaffee.web.msm.serializer.kryo.SpringSecurityUserRegistration"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
...

Just be warned: I haven't tested it, so I'm not sure if this really
solves the problem! ;-)
If you want to try please let me know how it works.

Cheers,
Martin


[1]
http://grepcode.com/file/repo1.maven.org/maven2/org.springframework.security/spring-security-core/3.0.5.RELEASE/org/springframework/security/core/userdetails/User.java#140


On 08/28/2013 06:22 PM, Netanel Weinberg wrote:
> Hi,
> I haven't understood the cause to the problem so I don't know how to fix
> it. For now, I've changed the serializer to be java's serializer and it
> works.
>
> Netanel
>
> בתאריך 28 באוג 2013 18:34, מאת "Martin Grotzke"
> <martin....@googlemail.com <mailto:martin....@googlemail.com>>:
signature.asc
Reply all
Reply to author
Forward
0 new messages