Giter VIP home page Giter VIP logo

session-managers's Introduction

‼️ The Sessions Managers repository will be archived at the end of the year 2020

This project has largely been inactive and will no longer be maintained once it is archived

Pivotal Session Managers

This project contains implementations of the Tomcat PersistentManager Store.

Implementation Description
redis-store Redis store backend

Contributing

Pull requests are welcome. See the contributor guidelines for details.

Builds

Each branch, release, and pull request kicks off builds on Travis CI

Logging

This project uses SLF4J and defaults to Java Utils Logging (JUL) binding

License

This project is released under the Apache License, Version 2.0.

session-managers's People

Contributors

ccheetham avatar jkonicki avatar mballoni avatar nebhale avatar pivmatt avatar sdiallo-talend avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

session-managers's Issues

SLF4J usage

Many libraries and projects today use SLF4J in order to provide a more flexible logging usage.
  It gives the developer the freedom to chose whatever log framework he or she wants.

  Jedis just aproved this same sort of migration:

  Https://github.com/xetorthio/jedis/issues/1340

  I think that this lib could follow the same example in order to follow this industry pattern and be more friendly with developers.

  I would also make a request with this feature that seems simple. May I?

Error while invoking read-locked operation

I've been developing on the following:
Windows 7
Java 1.7.0_80
Tomcat 8.0.26
Redis 3.2.4 (on Amazon ElastiCache)
redis-store-1.2.1.RELEASE.jar (downloaded from GitHub and stored in $TOMCAT/lib directory)

I added this to my context.xml file:

	<Valve className="com.gopivotal.manager.SessionFlushValve"/>
	
	<Manager className="org.apache.catalina.session.PersistentManager">
		<Store className="com.gopivotal.manager.redis.RedisStore"
			host="myredisserver.wzpuvj.ng.0001.apse1.cache.amazonaws.com"
			database="2"
			connectionPoolSize="100"
			timeout="10000"
		/>
	</Manager>

All is working fine in development. Today I installed on my test server, which is:
Ubuntu 12.04
Java 1.7.0_80
Tomcat 8.0.26
Redis 3.2.4 (on Amazon ElastiCache - same server as above)
redis-store-1.2.1.RELEASE.jar (downloaded from GitHub and stored in $TOMCAT/lib directory)

I added the same Valve and Manager elements to context.xml. Tomcat starts without error, however when I try and go to a page in the webapp I get this (repeated) in my catalina logs:

20-Sep-2017 13:18:06.964 SEVERE [ajp-nio-8009-exec-1] com.gopivotal.manager.LockTemplate.withReadLock Error while invoking read-locked operation
 java.lang.NullPointerException
        at com.gopivotal.manager.SessionFlushValve$7.invoke(SessionFlushValve.java:167)
        at com.gopivotal.manager.SessionFlushValve$7.invoke(SessionFlushValve.java:158)
        at com.gopivotal.manager.LockTemplate.withReadLock(LockTemplate.java:59)
        at com.gopivotal.manager.SessionFlushValve.invoke(SessionFlushValve.java:158)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
        at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:844)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)

I've also tried using versions 1.2.0, 1.3.0, 1.3.1 and 1.3.2 of the redis-store jar but all give the same error.

Support for Redis Sentinel

Hello,

We currently use Tomcat 7 and have a Redis HA setup that uses Redis Sentinel to monitor for failover. The Jedis library has support built-in to use Sentinel to determine the Redis master at any one time and to handle failover seamlessly. We would like to add support to redis-store for Sentinel.

I have the code ready to go, and would be happy to PR it if this team would be interested in having it.

Thanks!
Scott

Objects missing in session in non-sticky environment

I have moved my code onto an environment where I have two EC2 instances running Tomcat 8.0.24 being load balanced by ELB with stickiness disabled. The ELB switches between the two servers quite evenly. Both Tomcat instances are storing their sessions in an AWS ElastiCache Redis server.

What I'm finding is that objects stored in Redis are being lost, i.e. in one request I set a session attribute "myForm" (using redis-cli I can see that myForm is in the session). Then, a few minutes later I go to retrieve the object in another request and it's gone (as confirmed by redis-cli). I never remove the object from the session anywhere in my code and I've even set a breakpoint in Tomcat's StandardSessionFacade.removeAttribute() method and it never fires.

Sorry this is a bit vague but this is a mature and complex application and it's very hard to provide you steps to recreate. I'm using the Spring framework and myForm uses the @SessionAttributes and @ModelAttribute annotations - don't know if that's relevant.

If I disable one of the servers using the ELB (so that all traffic goes to a single server) everything works fine.

What could be useful is if I could get some debug info written to the logs for com.gopivotal. I tried adding "com.gopivotal.level = FINE" to the $TOMCAT/conf/logging.properties file but this didn't do anything.

Here are my configuration files (same on both servers). Thanks very much for your help!

$TOMCAT/conf/context.xml

<?xml version='1.0' encoding='utf-8'?>

<Context>

    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

    <!-- Start of additions by SJ for Redis integration -->
    <Valve className="com.gopivotal.manager.SessionFlushValve"/>

    <Manager className="org.apache.catalina.session.PersistentManager">
        <Store className="com.gopivotal.manager.redis.RedisStore"
            host="my-redis-cache.icdzqp.ng.0001.apse2.cache.amazonaws.com"
            database="2"
            connectionPoolSize="100"
            timeout="10000"
        />
    </Manager>
    <!-- End of additions by SJ for Redis integration -->

</Context>

$TOMCAT/conf/server.xml

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <Service name="Catalina">

    <Connector port="8080" protocol="HTTP/1.1" compression="on" noCompressionUserAgents="gozilla, traviata" scheme="https"
               proxyPort="443" proxyHost="localhost" connectionTimeout="20000" redirectPort="443" />

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               maxLogMessageBufferSize="512"
               pattern="%h %l %u %t &quot;%r&quot; %s %b %D %F" />

      </Host>
    </Engine>
  </Service>
</Server>

$TOMCAT/conf/Catalina/localhost/ROOT.xml

<Context
        docBase="/opt/MyApp/lba/my.war"
        unpackWAR="true"
        privileged="true"
        antiResourceLocking="false"
        reloadable="false">

      <Resource   name="jdbc/ConfigDB"
                 auth="Container"
                 type="javax.sql.DataSource"
                 maxTotal="5"
                 maxIdle="10"
                 maxWaitMillis="10000"
                 username="user"
                 password="password"
                 driverClassName="oracle.jdbc.driver.OracleDriver"
                 url="jdbc:oracle:thin:@10.222.5.30:1521:xe" />

        <Environment name="application" type="java.lang.String" value="common"/>
        <Environment name="environment" type="java.lang.String" value="staging"/>
        <Parameter name="log.file" value="/logconfig/log4j.xml" override="false"/>

</Context>

SEVERE: Error while invoking read-locked operation

Hi, I would like to ask what could be wrong on our setup. When I use the redis + tomcat +nginx. I don't get any error regarding Locktemplate but when we try to change the nginx and replace it with AWS Applcation Load balancer the Locktemplate shows in our logs.

Example Stacktrace:
Caused by: java.lang.ClassCastException: java.lang.StackTraceElement cannot be cast to java.lang.String at java.io.ObjectInputStream.readTypeString(ObjectInputStream.java:1612) at java.io.ObjectStreamClass.readNonProxy(ObjectStreamClass.java:719) at java.io.ObjectInputStream.readClassDescriptor(ObjectInputStream.java:882) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1815) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1713) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2000) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2169) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) at org.apache.catalina.session.StandardSession.doReadObject(StandardSession.java:1611) at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1077) at com.gopivotal.manager.SessionSerializationUtils.deserialize(SessionSerializationUtils.java:81) at com.gopivotal.manager.redis.RedisStore$22.invoke(RedisStore.java:442) at com.gopivotal.manager.redis.RedisStore$22.invoke(RedisStore.java:436) at com.gopivotal.manager.LockTemplate.withReadLock(LockTemplate.java:59) ... 24 more

Tomcat Version: 8.5.27
redis-store-1.3.2.RELEASE.jar
redis-3.2.10-2.el7.x86_64

Here's my context.xml.

<Valve className="com.gopivotal.manager.SessionFlushValve" /> <Manager className="org.apache.catalina.session.PersistentManager"> <Store className="com.gopivotal.manager.redis.RedisStore" host="10.10.5.226" port="6379"/> </Manager>

I've already saw some old issues regarding Locktemplate but none of them worked for me
(#48 )
(#20)

Any thoughts will be much appreciated.

SEVERE: Error while invoking read-locked operation

I get this error on saving a session:

SEVERE: Error while invoking read-locked operation
 java.lang.NullPointerException
	at com.gopivotal.manager.SessionFlushValve$7.invoke(SessionFlushValve.java:167)
	at com.gopivotal.manager.SessionFlushValve$7.invoke(SessionFlushValve.java:158)
	at com.gopivotal.manager.LockTemplate.withReadLock(LockTemplate.java:59)
	at com.gopivotal.manager.SessionFlushValve.invoke(SessionFlushValve.java:158)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.valves.CrawlerSessionManagerValve.invoke(CrawlerSessionManagerValve.java:180)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

I'm using Tomcat 7 and I downloaded session-managers v1.2.0. I ran mvn package and copied the redis-store-1.2.0.RELEASE.jar from the target directory to Tomcat/lib.

In my webapp's context.xml, I've added the following lines:

  <Valve className="com.gopivotal.manager.SessionFlushValve" />
  <Manager className="org.apache.catalina.session.PersistentManager">
    <Store
      className="com.gopivotal.manager.redis.RedisStore"
      connectionPoolSize="-1"
      database="1"
      host="localhost"
      port="6379"
      timeout="5000"
    />
  </Manager>

Error when using with Liferay CMS

I'm getting this error using the session manager with Liferay CMS. I suspect it's due to the content of the session not being serialisable as I've hit the same problem with another session manager. Any ideas how I might debug this?

May 23, 2017 8:23:40 AM com.gopivotal.manager.redis.RedisStore logAndCreateEmptySession
SEVERE: Unable to load session D09837183B2E37AA5000CE99CCF5500E. Empty session created.
java.lang.ClassNotFoundException: com.liferay.portlet.PortalPreferencesImpl
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:278)
        at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:625)
        at com.gopivotal.manager.SessionSerializationUtils$1.resolveClass(SessionSerializationUtils.java:71)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1612)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
        at org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1619)
        at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1084)
        at com.gopivotal.manager.SessionSerializationUtils.deserialize(SessionSerializationUtils.java:77)
        at com.gopivotal.manager.redis.RedisStore$20$1.invoke(RedisStore.java:484)
        at com.gopivotal.manager.redis.RedisStore$20$1.invoke(RedisStore.java:475)
        at com.gopivotal.manager.redis.JedisTemplate.withJedis(JedisTemplate.java:41)
        at com.gopivotal.manager.redis.RedisStore$20.invoke(RedisStore.java:475)
        at com.gopivotal.manager.redis.RedisStore$20.invoke(RedisStore.java:468)
        at com.gopivotal.manager.LockTemplate.withReadLock(LockTemplate.java:59)
        at com.gopivotal.manager.redis.RedisStore.load(RedisStore.java:468)
        at org.apache.catalina.session.PersistentManagerBase.swapIn(PersistentManagerBase.java:747)
        at org.apache.catalina.session.PersistentManagerBase.findSession(PersistentManagerBase.java:511)
        at org.apache.catalina.connector.Request.doGetSession(Request.java:2987)
        at org.apache.catalina.connector.Request.getSessionInternal(Request.java:2605)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:430)
        at com.gopivotal.manager.SessionFlushValve$7.invoke(SessionFlushValve.java:163)
        at com.gopivotal.manager.SessionFlushValve$7.invoke(SessionFlushValve.java:158)
        at com.gopivotal.manager.LockTemplate.withReadLock(LockTemplate.java:59)
        at com.gopivotal.manager.SessionFlushValve.invoke(SessionFlushValve.java:158)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)

com.gopivotal.manager.LockTemplate.withWriteLock - Error

I'm getting an error and am having a hard time figuring it out. com.gopivotal.manager.LockTemplate.withWriteLock Error while invoking write-locked operation. Is it just a rights issue somewhere? I appreciate any help you can provide.
2016-12-02_17-17-00

RedisStore does not support persistence across application restarts

To reload the session after Tomcat restarts, the RedisStore uses the SessionSerializationUtils class. A serialised session is retrieved from Redis as a byte array. SessionSerializationUtils simply delegates to the current thread's classloader, if the session contains user defined classes, the deserialisation would fail.

Instead of the current thread's classloader, the Tomcat webapp's classloader is supposed be used. See the sources of the default Tomcat's FileStore or JDBCStore.

v1.2.2 and v1.3.3 do not seem to work with java buildpack v3.18

It looks like the change to slf4j to set its scope as provided has stopped session managers working with the java buildpack. We have been able to successfully test using v1.2.1 and v1.3.2 and earlier without issue.

The error message we get when trying to stage apps is:

2017-07-13T09:36:59.39+0100 [APP/PROC/WEB/0] OUT [CONTAINER] org.apache.coyote.http11.Http11NioProtocol         INFO    Initializing ProtocolHandler ["http-nio-8080"]
2017-07-13T09:36:59.40+0100 [APP/PROC/WEB/0] OUT [CONTAINER] org.apache.catalina.startup.Catalina               INFO    Initialization processed in 386 ms
2017-07-13T09:36:59.42+0100 [APP/PROC/WEB/0] OUT [CONTAINER] org.apache.catalina.core.StandardService           INFO    Starting service Catalina
2017-07-13T09:36:59.42+0100 [APP/PROC/WEB/0] OUT [CONTAINER] org.apache.catalina.core.StandardEngine            INFO    Starting Servlet Engine: Apache Tomcat/8.0.44
2017-07-13T09:36:59.44+0100 [APP/PROC/WEB/0] OUT [CONTAINER] org.apache.catalina.startup.HostConfig             INFO    Deploying web application directory /home/vcap/app/.java-buildpack/tomcat/webapps/ROOT
2017-07-13T09:36:59.50+0100 [APP/PROC/WEB/0] OUT [CONTAINER] org.apache.tomcat.util.digester.Digester           SEVERE  Begin event threw error
2017-07-13T09:36:59.50+0100 [APP/PROC/WEB/0] OUT     at com.gopivotal.manager.AbstractLifecycle.<init>(AbstractLifecycle.java:50)
2017-07-13T09:36:59.50+0100 [APP/PROC/WEB/0] OUT     at com.gopivotal.manager.StandardLifecycleSupport.<init>(StandardLifecycleSupport.java:32)
2017-07-13T09:36:59.50+0100 [APP/PROC/WEB/0] OUT java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
2017-07-13T09:36:59.50+0100 [APP/PROC/WEB/0] OUT     at com.gopivotal.manager.SessionFlushValve.<init>(SessionFlushValve.java:53)
2017-07-13T09:36:59.50+0100 [APP/PROC/WEB/0] OUT     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
2017-07-13T09:36:59.50+0100 [APP/PROC/WEB/0] OUT     at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:117)
2017-07-13T09:36:59.50+0100 [APP/PROC/WEB/0] OUT     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
2017-07-13T09:36:59.50+0100 [APP/PROC/WEB/0] OUT     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1339)
2017-07-13T09:36:59.50+0100 [APP/PROC/WEB/0] OUT     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

Support for Redis Cluster

I believe the next big improvement for this lib is to add redis cluster support.
Using the newer Jedis lib version it is pretty simple to make it work.
Actually I've already done this in my fork and I'm willing to propose a pull request:

https://github.com/mballoni/session-managers/tree/master

The only problem that I managed to step was the lack of transaction support (multi command) with cluster and also twemproxy usage.
However it is only "necessary" in two or three points to guarantee multiple commands atomicity.
The side effect is not that bad after #21 since the key will eventually expire in the rare cases of inconsistence.

What do you think about it? Any thoughts?

tomcat 8 redis session store

I am trying to use this plugin in tomcat 8. Downloaded the latest code and did maven build add Valve and manager in context.xml, but when I bring up tomcat I am getting the following error

<Valve className="com.gopivotal.manager.PivotalSessionFlushValve" />
 <Manager className="org.apache.catalina.session.PersistentManager">
 <Store className="com.gopivotal.manager.redis.RedisStore"  host="localhost" port="6379"/>
</Manager>

25-Oct-2016 15:36:45.145 SEVERE [localhost-startStop-1] com.gopivotal.manager.LockTemplate.withReadLock Error while invoking read-locked operation
java.lang.IllegalArgumentException: javax.management.InstanceAlreadyExistsException: Catalina:type=Valve,context=/,host=localhost,name=PivotalSessionFlushValve
at com.gopivotal.manager.StandardJmxSupport.register(StandardJmxSupport.java:47)
at com.gopivotal.manager.PivotalSessionFlushValve$8.invoke(PivotalSessionFlushValve.java:177)
at com.gopivotal.manager.PivotalSessionFlushValve$8.invoke(PivotalSessionFlushValve.java:173)
at com.gopivotal.manager.LockTemplate.withReadLock(LockTemplate.java:59)
at com.gopivotal.manager.PivotalSessionFlushValve.startInternal(PivotalSessionFlushValve.java:173)
at com.gopivotal.manager.AbstractLifecycle.start(AbstractLifecycle.java:122)
at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:170)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5214)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1092)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1834)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
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)
Caused by: javax.management.InstanceAlreadyExistsException: Catalina:type=Valve,context=/,host=localhost,name=PivotalSessionFlushValve
at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324)
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
at com.gopivotal.manager.StandardJmxSupport.register(StandardJmxSupport.java:45)
... 19 more

I tried changing the name of the Valve class to PivotalSessionFlushValve, still gave the same error instancealreadyexists.

Please let me know If I am missing anything.

Unable to load session

After I restart Tomcat, where I run Grails application, next error appears in log:

21-Mar-2016 18:06:53.880 SEVERE [http-apr-8080-exec-2] null.null Unable to load session 995B6620B99D252181CEA807888F58C8. Empty session created.
java.lang.ClassNotFoundException: org.codehaus.groovy.grails.web.servlet.GrailsFlashScope
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
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:344)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:626)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at org.apache.catalina.session.StandardSession.doReadObject(StandardSession.java:1634)
at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1099)
at com.gopivotal.manager.SessionSerializationUtils.deserialize(SessionSerializationUtils.java:67)
at com.gopivotal.manager.redis.RedisStore$20$1.invoke(RedisStore.java:477)
at com.gopivotal.manager.redis.RedisStore$20$1.invoke(RedisStore.java:468)
at com.gopivotal.manager.redis.JedisTemplate.withJedis(JedisTemplate.java:41)
at com.gopivotal.manager.redis.RedisStore$20.invoke(RedisStore.java:468)
at com.gopivotal.manager.redis.RedisStore$20.invoke(RedisStore.java:461)
at com.gopivotal.manager.LockTemplate.withReadLock(LockTemplate.java:59)
at com.gopivotal.manager.redis.RedisStore.load(RedisStore.java:461)
at org.apache.catalina.session.PersistentManagerBase.swapIn(PersistentManagerBase.java:727)
at org.apache.catalina.session.PersistentManagerBase.findSession(PersistentManagerBase.java:490)
at org.apache.catalina.connector.Request.doGetSession(Request.java:2855)
at org.apache.catalina.connector.Request.getSession(Request.java:2254)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:895)
at org.codehaus.groovy.grails.web.servlet.DefaultGrailsApplicationAttributes.getFlashScope(DefaultGrailsApplicationAttributes.java:1
69)
at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:64)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at com.gopivotal.manager.SessionFlushValve$7.invoke(SessionFlushValve.java:163)
at com.gopivotal.manager.SessionFlushValve$7.invoke(SessionFlushValve.java:158)
at com.gopivotal.manager.LockTemplate.withReadLock(LockTemplate.java:59)
at com.gopivotal.manager.SessionFlushValve.invoke(SessionFlushValve.java:158)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:283)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2463)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2452)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

Could you please help me to fix this?

Support redis clustering for non-sticky sessions

I'd like to setup tomcat clustering with redis without sticky sessions.

I believe this is not supported by the library and hence would like :

  • to have confirmation
  • to check if it's doable to implement such support (i.e. via PR) - I don't think so using the tomcat Store approach but perhaps I'm wrong (I hope so !).

I use the following context.xml :

	<!--
     Each processExpiresFrequency of tomcat backgroundThreadExecution,
     the manager will check if the session need to be swapped from in-memory
     to the store (redis) - which will be the case after 10s of idle.
    -->
	<Manager className="org.apache.catalina.session.PersistentManager"
			 processExpiresFrequency="1"
			 maxIdleSwap="10"
			 minIdleSwap="10">
        <Store className="com.gopivotal.manager.redis.RedisStore"
               host="${redis.sessions.host}"
               port="${redis.sessions.port}"
               database="${redis.sessions.database}"/>
	</Manager>

Setup explanations:
I needed to setup maxIdleSwap and minIdleSwap to for in-memory sessions to be swapped to redis.
Otherwise, PersistenceManagerBase#findSession will try to get the session from memory (ManagerBase#sessions hashmap) and if it finds it, it doesn't get the session from Redis.

Problems found
But even having this setup, I cannot support non sticky scenario :
tomcat swaps out sessions from in-memory to Store (redis) in a background thread (the swapOut method will be called every processExpiresFrequency * backgroundProcessorDelay - aka every 10sec in my scenario and swaps out sessions idled for more than maxIdleSwap secs).

Even setting if I setup this to a lower value, I can run in the following scenario :
a - browser request1 handled by Tomcat instance1 and updating session
b - browser request2 handled by Tomcat instance2 and updating session
c - browser request3 handled by Tomcat instance1 and updating session
if execution time between a and c is less than the swapOut time, then request c will use and old session state (state from a instead of state from b).

The only way to support a non sticky scenario would be to call PersistentManagerBase#swapOut(Session) method but this one is protected.

Thanks,
Adrian

P.S. : on a related topic, if a request is running for more than processExpiresFrequency*backgroundProcessorDelay + minIdleSwap then the session is swapped out
while it's used.
This prevents us to use a small value for minIdleSwap otherwise, session could be null in the middle of a request execution.

session ttl always set to -1

my redis session's ttl always set to -1
using session-managers-1.2.0.RELEASE.
and my tomcat is 7.0.67
my server is on aws ec2 machine (amazon linux)

I check time property is set right. but ttl set to -1...
(check by logging at RedisStore.java )

someone help plz.

  • it expires... but not expected like i set in the context.xml...

Document Redis key expiry

It looks like keys are expired from Redis using the Tomcat session expiry settings, normally in conf/web.xml

#21

This is a key detail as some people may expect the key count to vary based on logging out of an application.

log important redis-store events

There are several events for which a log entry (or so) will help to quickly verify redis-store is deployed/running as expected.

  • Upon startup, redis-store should log it's "about" information, e.g. version. This information is useful for both operations and development.

  • When properties are set, redis-store should log the event. E.g., if context.xml is edited for a property change for a live instance, that information should be logged. Currently, the only such information is done at initial connection. If a property changes, the current value will be different than that of the last log referencing that value.

Document persistence manager options and the use of com.gopivotal.manager.SessionFlushValve

The Tomcat persistence manager documentation is pretty lacking. Many people are asking for more detail in the comments section.

When using this manager for a shared session store (possibly what it was not originally designed for) many write ups list the time delay between the creating a session and flushing the sessions to the store being a issue with non-sticky sessions. I assume that this valve is some way of mitigating this:-

<Valve className="com.gopivotal.manager.SessionFlushValve" />

Here's the best description of the params that I found:-

<Context>

...

    <!-- The idle time in seconds before persisting session is
         maxIdleBackup + processExpiresFrequency * engine.backgroundProcessorDelay.
         The backgroundProcessorDelay is around 10 seconds. This configuration should make Tomcat
         to persist sessions after 20 seconds of idling and hold them in memory as long as each
         instance wants -->
    <Manager className="org.apache.catalina.session.PersistentManager"
      saveOnRestart="true"
      minIdleSwap="-1"
      maxIdleSwap="-1"
      maxIdleBackup="20"
      processExpiresFrequency="1">
      <Store className="org.apache.catalina.session.JDBCStore"
        connectionURL="jdbc:mysql://localhost/tomcat_data"
        driverName="com.mysql.jdbc.Driver"
        connectionName="tomcat"
        connectionPassword="tomcat"
        sessionIdCol="session_id"
        sessionValidCol="valid_session"
        sessionMaxInactiveCol="max_inactive"
        sessionLastAccessedCol="last_access"
        sessionTable="tomcat_sessions"
        sessionAppCol="app_name"
        sessionDataCol="session_data"
      />
    </Manager>
...

</Context>


Problems in this solution

If Tomcat dies unexpectedly, the new sessions served by dead instance are lost. Most likely with the configuration above, sessions newer than 30 seconds will disappear. Also new changes that have been done to session data will be lost.

http://pedanttinen.blogspot.co.uk/2012/01/tomcat-clustering-and-session.html

add redis key prefix

I'd like to suggest a new feature.

To be able to specify a redis key prefix, make it easier to flush all sessions for specific apps/context.

If you think that's a good idea I'll work on a pull request for it.

Broken resource returned twice to the pool

Making some crash tests I noted that broken resources are returned twice to the pool:
https://github.com/pivotalsoftware/session-managers/blob/master/redis-store/src/main/java/com/gopivotal/manager/redis/JedisTemplate.java#L42

Checking the jedis docs I came across this issue that explains the problem as well as the solution description:
redis/jedis#476

Do you agree with this issue? I only ask because the tests requires it to be returned twice (one broken and one "normal").

I would gladly make a pull request to fix this, can I? I just checked the contribution guidelines.

Tomcat instances share session

Hello,

I have a swarm cluster with two tomcat replicas running. Tomcat is configured with Pivotal Session Managers. When I log in to one tomcat, the login does not reflect the other replica. Using this plugin, should replicas share the same session?

Thaks!

Archiving project

This is no longer an actively maintained project. As noted on the Readme it will be archive as of year end 2020.

Thank you to the community for all the contributions.

consolidate 1.2 and 1.3 into a single code base

1.3 introduced support for Tomcat 8.5 (API changes). These changes were intentionally kept separate for the purpose of expediency in resolving 8.5 incompatibilities.

However, at some point we should consolidate into a single codebase/release.

Several benefits:

  • reduce misconfiguration opportunity; for both deployments and dependent projects
  • simplify development by reducing merge workflow
  • help future-proof against Tomcat API changes; when API changes, framework will already be in place

A possible approach would:

  • create branch 1.3 for deprecated releases
    • 1.2 fixes merged to 1.3 if needed
    • 1.3 a deadend branch
  • create 2.0 branch (could remain master) for continuing development

SSL

Hi,

Many thanks for providing this.

Does it support SSL redis connections?

Thanks!
Mark

unit tests output white noise

Although tests pass, test output includes strack traces/and logging. In addition to being a red herring nuisance, unexpected stack traces or output may be missed.

Example:

INFO: Closing connection to Redis Server
Mar 15, 2017 10:38:46 AM com.gopivotal.manager.redis.RedisStore$21 invoke
SEVERE: Unable to remove session test-id
redis.clients.jedis.exceptions.JedisConnectionException: test-message
	at com.gopivotal.manager.redis.JedisTemplate.withJedis(JedisTemplate.java:40)
...

Tests should not intentionally produce stdout output.

It's possible (likely?) that the resolution for #16 will help mitigate this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.