Message Boards

Session event listener threw exception java.lang.NullPointerException.

Maulin Patel, modified 3 Years ago.

Session event listener threw exception java.lang.NullPointerException.

New Member Posts: 9 Join Date: 6/16/20 Recent Posts
I am implementing Clustering (Session Replication) of two liferay + Tomcat instances over the intranet using unicast,  but i am facing Null Pointer Exception. Please find below details.

Tomcat instance 1 Server.xml file : <Cluster 
            channelSendOptions="8" 
            channelStartOptions="3" 
            className="org.apache.catalina.ha.tcp.SimpleTcpCluster">    <Manager 
            className="org.apache.catalina.ha.session.DeltaManager" 
            expireSessionsOnShutdown="false" 
            notifyListenersOnReplication="true"/>
    
    <Channel className="org.apache.catalina.tribes.group.GroupChannel">
        <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
        </Sender>
        <Receiver 
            address="192.168.1.183" 
            autoBind="0" 
            className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
            maxThreads="6" 
            port="4000" 
            selectorTimeout="5000" 
        />
        <!-- <Interceptor className="com.dm.tomcat.interceptor.DisableMulticastInterceptor" /> -->
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor" staticOnly="true"/>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
        <Member 
            className="org.apache.catalina.tribes.membership.StaticMember" 
            port="4000"
            host="192.168.1.135" 
            uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2}" 
        />
        </Interceptor>
    </Channel>
    <Valve 
        className="org.apache.catalina.ha.tcp.ReplicationValve" 
        filter=".*.gif;.*.js;.*.jpg;.*.png;.*.htm;.*.html;.*.css;.*.txt;" 
    />
        <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
         
        <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
        <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
         
    </Cluster>Tomcat instance 2 Server.xml file : 
<Cluster 
            channelSendOptions="8" 
            channelStartOptions="3" 
            className="org.apache.catalina.ha.tcp.SimpleTcpCluster">    <Manager 
            className="org.apache.catalina.ha.session.DeltaManager" 
            expireSessionsOnShutdown="false" 
            notifyListenersOnReplication="true"/>
    
    <Channel className="org.apache.catalina.tribes.group.GroupChannel">
        <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
        </Sender>
        <Receiver 
            address="192.168.1.135" 
            autoBind="0" 
            className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
            maxThreads="6" 
            port="4000" 
            selectorTimeout="5000" 
        />
        <!-- <Interceptor className="com.dm.tomcat.interceptor.DisableMulticastInterceptor" /> -->
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor" staticOnly="true"/>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
        <Interceptor       className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
        <Member 
            className="org.apache.catalina.tribes.membership.StaticMember" 
            port="4000"
            host="192.168.1.183" 
            uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9}" 
        />
        </Interceptor>
    </Channel>
    <Valve 
        className="org.apache.catalina.ha.tcp.ReplicationValve" 
        filter=".*.gif;.*.js;.*.jpg;.*.png;.*.htm;.*.html;.*.css;.*.txt;" 
    />
    <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
         
        <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
    </Cluster>
I have added <distributable/> in ROOT\WEB-INF\web.xml in both the tomcat instances. Both the machine are connected with each other over the VPN and we have open all the required port. Below is the exception i am facing.ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/]] - Session event listener threw exception
java.lang.NullPointerException
    at com.liferay.portal.kernel.servlet.filters.compoundsessionid.CompoundSessionIdSplitterUtil.hasSessionDelimiter(CompoundSessionIdSplitterUtil.java:36)
    at com.liferay.portal.kernel.servlet.PortletSessionListenerManager.getHttpSessionEvent(PortletSessionListenerManager.java:86)
    at com.liferay.portal.kernel.servlet.PortletSessionListenerManager.sessionCreated(PortletSessionListenerManager.java:50)
    at org.apache.catalina.session.StandardSession.tellNew(StandardSession.java:423)
    at org.apache.catalina.session.StandardSession.setId(StandardSession.java:395)
    at org.apache.catalina.ha.session.DeltaSession.setId(DeltaSession.java:277)
    at org.apache.catalina.ha.session.DeltaManager.handleSESSION_CREATED(DeltaManager.java:1406)
    at org.apache.catalina.ha.session.DeltaManager.messageReceived(DeltaManager.java:1284)
    at org.apache.catalina.ha.session.DeltaManager.messageDataReceived(DeltaManager.java:1014)
    at org.apache.catalina.ha.session.ClusterSessionListener.messageReceived(ClusterSessionListener.java:92)
    at org.apache.catalina.ha.tcp.SimpleTcpCluster.messageReceived(SimpleTcpCluster.java:940)
    at org.apache.catalina.ha.tcp.SimpleTcpCluster.messageReceived(SimpleTcpCluster.java:921)
    at org.apache.catalina.tribes.group.GroupChannel.messageReceived(GroupChannel.java:278)
    at org.apache.catalina.tribes.group.ChannelInterceptorBase.messageReceived(ChannelInterceptorBase.java:84)
    at org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor.messageReceived(TcpPingInterceptor.java:170)
    at org.apache.catalina.tribes.group.ChannelInterceptorBase.messageReceived(ChannelInterceptorBase.java:84)
    at org.apache.catalina.tribes.group.interceptors.TcpFailureDetector.messageReceived(TcpFailureDetector.java:114)
    at org.apache.catalina.tribes.group.ChannelInterceptorBase.messageReceived(ChannelInterceptorBase.java:84)
    at org.apache.catalina.tribes.group.ChannelInterceptorBase.messageReceived(ChannelInterceptorBase.java:84)
    at org.apache.catalina.tribes.group.ChannelCoordinator.messageReceived(ChannelCoordinator.java:253)
    at org.apache.catalina.tribes.transport.ReceiverBase.messageDataReceived(ReceiverBase.java:287)
    at org.apache.catalina.tribes.transport.nio.NioReplicationTask.drainChannel(NioReplicationTask.java:212)
    at org.apache.catalina.tribes.transport.nio.NioReplicationTask.run(NioReplicationTask.java:101)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Maulin Patel, modified 3 Years ago.

RE: Session event listener threw exception java.lang.NullPointerException.

New Member Posts: 9 Join Date: 6/16/20 Recent Posts
This exception comes after the first instance of tomcat starts and while starting the second instance of tomcat.
thumbnail
Olaf Kock, modified 3 Years ago.

RE: Session event listener threw exception java.lang.NullPointerException.

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Maulin Patel:

I am implementing Clustering (Session Replication) of two liferay + Tomcat instances over the intranet using unicast,  but i am facing Null Pointer Exception.
Did you already configure clustering correctly without session replication, but sticky sessions instead?
That's typically what covers 99% of usecases, and is necessary anyway, so my recommendation is to nail this first, before continuing  with the appserver extras.
And a quick actionable guess: Did you configure the jvmRoute for your tomcat nodes?
Maulin Patel, modified 3 Years ago.

RE: Session event listener threw exception java.lang.NullPointerException.

New Member Posts: 9 Join Date: 6/16/20 Recent Posts
Thank you for  replying Olaf,

Currently I have just implemented session replication didn't implemented sticky session. I am doing this for high availability and our first step  towards that is implementing session replication in tomcat instances. I am implementing this through unicast.

​​​​​​​I have already mentioned configuration i have implemented as above. Still i am facing the Null Pointer Exception while starting the second server. 
please let me know if i am missing something.
thumbnail
Olaf Kock, modified 3 Years ago.

RE: Session event listener threw exception java.lang.NullPointerException.

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Maulin Patel:

​​​​​​​I have already mentioned configuration i have implemented as above.
That's why I've asked. The configuration that you provided is an optional (and often discouraged) way to configure a cluster. You didn't mention anything about the underlying  and necessary Liferay-cluster configuration. Even with session replication you should implement sticky sessions.
Make sure you implement Liferay clustering first, with sticky sessions. That's already highly available and you might get marginally better availability (at the cost of a lowered performance) with session replication.
Maulin Patel, modified 3 Years ago.

RE: Session event listener threw exception java.lang.NullPointerException.

New Member Posts: 9 Join Date: 6/16/20 Recent Posts
Hi Olaf,
As you said I have implemented full clustering including liferay side changes and configure load balancer as well. But i am still have this Null Pointer Exception at the time of starting the server.

And one more question I would like to ask that at my application i have used static map and managing it to local cache. But now as I have implemented clustering i need to distribute that cache over the cluster as well. So is there any way to do that?
thumbnail
Olaf Kock, modified 3 Years ago.

RE: Session event listener threw exception java.lang.NullPointerException.

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Re NPE:

Looking at the incriminated code in CompoundSessionIdSplitterUtil.hasSessionDelimiter(CompoundSessionIdSplitterUtil.java:36), I don't see anything suspicious - however, there's a static constructor block in that class and it might be involved. However, I only see any reference to Weblogic in there.

Repeating my question: Did you configure any jvmRoute in server.xml? It's not part of your server.xml quoted in your original question, and I feel it's required. Tomcat's balanced session ids look something like "0123456789ABCDEF;node1" (from memory), note the jvmRoute tacked to the regular session id with a semicolon. This is so that the loadbalancer has a clue where to direct the next request to (i.e. sticky sessions)

Re  Custom Cache implementation:
If you implement your own cache: Yes, you'll have to do what Liferay did to communicate changes across the cluster. You could also just use Liferay's cache implementation. Note that typically no cache is replicated across the cluster: It's just invalidated. Only in case an object is required on another node, will it be loaded into cache after being invalidated. There's no need for all cluster machines holding identical caches. Each is serving its own content.
Maulin Patel, modified 3 Years ago.

RE: Session event listener threw exception java.lang.NullPointerException.

New Member Posts: 9 Join Date: 6/16/20 Recent Posts
Hi Olaf,
Thank you for your reply and sorry for my late reply.
As you have suggested I have added jvmRoute in server.xml but still I am having the same error.