Caught CNFE decoding ... bytes of data: class not found

1,807 views
Skip to first unread message

mj

unread,
Aug 16, 2011, 2:43:16 PM8/16/11
to memcached-session-manager
Configured similar to the demo. Run two tomcats on the same box, each
has the same web app files physically deployed (not a link). On the
same box, run two instances of memcached.

Here's relevant settings in context.xml.

<Manager
className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
sticky="true"
memcachedNodes="n1:localhost:11211 n2:localhost:11212"
failoverNodes="n1"
requestUriIgnorePattern=".*\.(png|gif|jpg|css|js|ico)$"
sessionBackupAsync="false"
sessionBackupTimeout="100"

transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>

In the log, I noticed the following warning where "a.b.c.d.ClassName"
is a class in my web application. It seems that SerializingTranscoder
cannot find the class to do serde? But the web applications run just
fine. What's happening here? Thanks!

2011-08-16 11:18:43.679 WARN
net.spy.memcached.transcoders.SerializingTranscoder: Caught CNFE
decoding 495 bytes of data

java.lang.ClassNotFoundException: a.b.c.d.ClassName
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at
java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:603)
at
java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:
1574)
at
java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
at
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:
1731)
at
java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:
350)
at
net.spy.memcached.transcoders.BaseSerializingTranscoder.deserialize(BaseSerializingTranscoder.java:
100)
at
net.spy.memcached.transcoders.SerializingTranscoder.decode(SerializingTranscoder.java:
66)
at net.spy.memcached.transcoders.TranscodeService
$1.call(TranscodeService.java:42)
at java.util.concurrent.FutureTask
$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at net.spy.memcached.transcoders.TranscodeService
$Task.run(TranscodeService.java:89)
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:680)

Martin Grotzke

unread,
Aug 16, 2011, 3:31:46 PM8/16/11
to memcached-se...@googlegroups.com
Hi,

which version of memcached-session-manager are you using
(core/tomcat6/tomcat7/kryo)?
Which jars do you have in tomcat's lib dir, which jars in WEB-INF/lib
(complete listings)?
Do you have other exceptions/stack traces in the log file? I'm
especially missing the thread that triggered spymemcached...

Cheers,
Martin

--
Dennis Brakhane, Martin Grotzke und Ole Langbehn GbR
Breitenfelder Str. 13c, 20251 Hamburg

signature.asc

Michael Jiang

unread,
Aug 16, 2011, 5:36:36 PM8/16/11
to memcached-se...@googlegroups.com
Uh, it happens even w/o msm settings. Seems to be my web application deployment problem.

Thanks for help!

-mJ

Martin Grotzke

unread,
Aug 16, 2011, 5:43:12 PM8/16/11
to memcached-se...@googlegroups.com
On 08/16/2011 11:36 PM, Michael Jiang wrote:
> Uh, it happens even w/o msm settings. Seems to be my web application
> deployment problem.
Are you using spymemcached in your application? Then the issue might be
that there's the spymemcached jar in tomcat's lib dir: it's used by the
classloader instead of the one in WEB-INF/lib and the one in
CATALINA_HOME/lib doesn't know about your apps classes. So it should
work when you remove the one from CATALINA_HOME/lib. Is this the case?

Cheers,
Martin

signature.asc

Michael Jiang

unread,
Aug 16, 2011, 6:00:14 PM8/16/11
to memcached-se...@googlegroups.com
Martin,

That's exactly the case. Because the memcached loaded from tomcat's lib knows nothing about my web app classes. But now it's a different question, if I remove the memcached lib from tomcat lib folder, msm will complain no "net/spy/memcached/transcoders/SerializingTranscoder" found. How to solve that? Thanks!

Martin Grotzke

unread,
Aug 16, 2011, 6:32:24 PM8/16/11
to memcached-se...@googlegroups.com
On 08/17/2011 12:00 AM, Michael Jiang wrote:
> Martin,
>
> That's exactly the case. Because the memcached loaded from tomcat's lib
> knows nothing about my web app classes. But now it's a different
> question, if I remove the memcached lib from tomcat lib folder, msm will
> complain no "net/spy/memcached/transcoders/SerializingTranscoder" found.
> How to solve that? Thanks!
One solution would be to serialize your classes by hand (to a byte[],
using java ser or kryo or anything else) and store this byte[] in memcached.
I'm still thinking about another solution, that's the first one coming
to my mind.

Perhaps another option would be to load the MemcachedClient using the
classloader of one of your apps classes - not sure if this works. The
problem will probably be to assign it to a field of type MemcachedClient:
Object mcObj = SomeOfYourClasses.class.getClassLoader()
.loadClass("net.spy.memcached.MemcachedClient").newInstance();
MemcachedClient mc = (MemcachedClient)mcObj;
// the last line will probably throw a ClasscastException telling you
that MemcachedClient cannot be cast to MemcachedClient.

Hopefully the first one is an option for you :-)

Cheers,
Martin

signature.asc

Martin Grotzke

unread,
Aug 16, 2011, 7:16:01 PM8/16/11
to memcached-se...@googlegroups.com

Probably we could also improve msm to load the MemcachedClient optionally from WEB-INF/lib. Do you want to submit an issue for this?

Cheers,
Martin

Michael Jiang

unread,
Aug 16, 2011, 7:46:08 PM8/16/11
to memcached-se...@googlegroups.com
Actually I feel a bit confused. If I put a copy of memcached in $CATALINA_HOME/lib and another copy in WEB-INF/lib of web app, considering a class is defined by both class loader and class name, shouldn't the one in web app's lib folder be loaded as well? If that's true, that'll solve the problem. But apparently it's not. Any comments? I am confused and need a tutorial :)

Martin Grotzke

unread,
Aug 17, 2011, 6:09:45 AM8/17/11
to memcached-se...@googlegroups.com
On 08/17/2011 01:46 AM, Michael Jiang wrote:
> Actually I feel a bit confused. If I put a copy of memcached in
> $CATALINA_HOME/lib and another copy in WEB-INF/lib of web app,
> considering a class is defined by both class loader and class name,
> shouldn't the one in web app's lib folder be loaded as well? If that's
> true, that'll solve the problem. But apparently it's not. Any comments?
> I am confused and need a tutorial :)

Sorry for confusion :-) When I said "load the MemcachedClient optionally
from WEB-INF/lib" I left out "... when MemcachedClient is not available
in $CATALINA_HOME/lib". Though, I had a quick look at it, and it would
be some effort, as all "hard" references on MemcachedClient would have
to be removed in msm and replaced by some indirection.

Is it an option for you to serialize/deserialize beans and store the
byte[] in memcached?

Cheers,
Martin

signature.asc
Reply all
Reply to author
Forward
0 new messages