Bug 60806

Summary: Problem with ServletContext replication
Product: Tomcat 8 Reporter: Andrew Gillett <asgillett>
Component: ClusterAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 8.5.11   
Target Milestone: ----   
Hardware: PC   
OS: Linux   

Description Andrew Gillett 2017-03-02 20:13:30 UTC
Environment:
  Apache Tomcat 8.5.11
  OpenJDK Runtime Environment (build 1.8.0_121-b13)
  Centos 7.3 (64 bit)

I have a two node Tomcat cluster (server1 & server2) with an Apache load balancer.

Context replication is enabled with:
    <Context className="org.apache.catalina.ha.context.ReplicatedContext"/>
in META-INF/context.xml, and
    <distributable/>
in WEB-INF/web.xml.

When I place an object in the server1 ServletContext I see the following error on server2:

02-Mar-2017 11:31:28.088 SEVERE
[Tribes-Task-Receiver[Catalina-Channel]-3]
org.apache.catalina.tribes.tipis.AbstractReplicatedMap.messageReceived
Unable to deserialize MapMessage.
 java.lang.ClassNotFoundException: com.pharmhos.merlin.jaas.AdUser
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:677)
        at org.apache.catalina.tribes.io.ReplicationStream.resolveClass(ReplicationStream.java:79)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1819)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1713)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1986)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422)
        at org.apache.catalina.tribes.io.XByteBuffer.deserialize(XByteBuffer.java:558)
        at org.apache.catalina.tribes.tipis.AbstractReplicatedMap$MapMessage.value(AbstractReplicatedMap.java:1504)
        at org.apache.catalina.tribes.tipis.AbstractReplicatedMap$MapMessage.deserialize(AbstractReplicatedMap.java:1462)
        at org.apache.catalina.tribes.tipis.AbstractReplicatedMap.messageReceived(AbstractReplicatedMap.java:649)
        at org.apache.catalina.tribes.group.GroupChannel.messageReceived(GroupChannel.java:300)
        at org.apache.catalina.tribes.group.ChannelInterceptorBase.messageReceived(ChannelInterceptorBase.java:83)
        at org.apache.catalina.tribes.group.ChannelInterceptorBase.messageReceived(ChannelInterceptorBase.java:83)
        at org.apache.catalina.tribes.group.interceptors.TcpFailureDetector.messageReceived(TcpFailureDetector.java:116)
        at org.apache.catalina.tribes.group.ChannelInterceptorBase.messageReceived(ChannelInterceptorBase.java:83)
        at org.apache.catalina.tribes.group.ChannelCoordinator.messageReceived(ChannelCoordinator.java:276)
        at org.apache.catalina.tribes.transport.ReceiverBase.messageDataReceived(ReceiverBase.java:244)
        at org.apache.catalina.tribes.transport.nio.NioReplicationTask.drainChannel(NioReplicationTask.java:213)
        at org.apache.catalina.tribes.transport.nio.NioReplicationTask.run(NioReplicationTask.java:101)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

It appears that my AdUser object is being serialized on server1 but is not being deserialized on server2.

The "AdUser" class exists within the web application under WEB-INF/classes but it looks like the org.apache.catalina.tribes.io.ReplicationStream is not finding the right class loader for the web app.

According to <kfujino@apache.org>:
> This seems to ReplicatedContext's bug.
> In the current code, the class loader is passed to ReplicationMap as Null.
> It is necessary to call super.startInternal() before initializing the ReplicationMap.
Comment 1 Keiichi Fujino 2017-03-06 08:52:58 UTC
The fix will be in :
- 9.0.x for 9.0.0.M18 onwards
- 8.5.x for 8.5.12 onwards
- 8.0.x for 8.0.42 onwards
- 7.0.x for 7.0.76 onwards