hazelcast / hazelcast-tomcat-sessionmanager

Tomcat Based Web Session Replication
Other
33 stars 37 forks source link

NPE when starting Hazelcast Client in embedded Tomcat 8 #53

Closed tortarga closed 5 years ago

tortarga commented 6 years ago

NPE when starting Hazelcast Client in embedded Tomcat 8

Embedded Tomcat Version: 8.0.30 Hazelcast version: 3.1.1 HazelcastSessionManager version: hazelcast-tomcat8-sessionmanager-1.1.3

Running embedded tomcat and setting hazelcast via:

      // ...
      // Tomcat creation and context setting
      // ...
      // Hazelcast Config
      HazelcastSessionManager hazelcastSessionManager = new HazelcastSessionManager();
      hazelcastSessionManager.setClientOnly(true);
      hazelcastSessionManager.setSticky(true);
      standardContext.setManager(hazelcastSessionManager);
      standardContext.addLifecycleListener(new ClientServerLifecycleListener());
      tomcat.start();

Results in following NPE:

com.hazelcast.session.HazelcastSessionManager startInternal
SEVERE: Hazelcast Client could not be created. 
java.lang.NullPointerException
    at com.hazelcast.session.HazelcastSessionManager.startInternal(HazelcastSessionManager.java:92)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5272)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
    at java.util.concurrent.FutureTask.run(FutureTask.java)
    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)

Nov 14, 2018 3:12:39 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: The session manager failed to start
org.apache.catalina.LifecycleException: Failed to start component [com.hazelcast.session.HazelcastSessionManager[/pbrc]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5272)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
    at java.util.concurrent.FutureTask.run(FutureTask.java)
    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)
Caused by: org.apache.catalina.LifecycleException
    at com.hazelcast.session.HazelcastSessionManager.startInternal(HazelcastSessionManager.java:96)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 9 more

After running through debugger in IntelliJ:

When in client mode HazelcastSessionManager attempts to retrieve client config from ClientServerLifecycleListener within the startInternal method.

ClientConfig is only created in ClientServerLifecycleListener on the Tomcat "start" LifeCycle event, which occurs after the state change so is never created in time for the session manager to use.