memcached-session-manager icon indicating copy to clipboard operation
memcached-session-manager copied to clipboard

New session for every request

Open rpvilao-gymondo opened this issue 8 years ago • 3 comments

Hi,

I guess this is not a real issue, but more some kind of misconfiguration, but I already exhausted the whole internet with searches and I cannot seem to find a solution or even understand what the hell is going on.

The problem: For every new request I get a new session, even though memcached seems to be in place and there are no errors on the console.

Setup:

  • Tomcat 7.0.77
  • Memcached 1.4.34 from AWS (1 node only) (connectivity is not a problem, I can telnet there)
  • Libs (tomcat/lib): AmazonElastiCacheClusterClient-1.1.1.jar memcached-session-manager-1.8.2.jar memcached-session-manager-tc7-1.8.2.jar

I'm also only running one tomcat node, since I get it to fail also with one.

ROOT.xml (conf/Catalina/localhost/ROOT.xml)

<Context path="" useHttpOnly="true">
    <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
        memcachedNodes="COMPANY20-test.dcsnk0.cfg.euw1.cache.amazonaws.com:11211"
        sticky="false"
        sessionBackupAsync="true"
        lockingMode="none"
        requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
        transcoderFactoryClass="de.javakaffee.web.msm.JavaSerializationTranscoderFactory"
    />
</Context>

Logging for configuration:

2017-04-25 13:41:31 [pool-4-thread-1]: INFO  net.spy.memcached.ConfigurationPoller - Starting configuration poller.
2017-04-25 13:41:31 [pool-4-thread-1]: INFO  net.spy.memcached.ConfigurationPoller - Endpoint to use for configuration access in this poll NodeEndPoint - HostName:COMPANY20-test.dcsnk0.0001.euw1.cache.amazonaws.com IpAddress:172.31.3.22 Port:11211
2017-04-25 13:41:31 [pool-4-thread-1]: WARN  net.spy.memcached.ConfigurationPoller - Change in configuration - Existing configuration: Version:-1  CacheNode List:
 New configuration:Version:1  CacheNode List: COMPANY20-test.dcsnk0.0001.euw1.cache.amazonaws.com:11211
2017-04-25 13:41:31 [pool-4-thread-1]: INFO  net.spy.memcached.ConfigurationPoller - Notifying observers about configuration change.
2017-04-25 13:42:31 [pool-4-thread-1]: INFO  net.spy.memcached.ConfigurationPoller - Starting configuration poller.
2017-04-25 13:42:31 [pool-4-thread-1]: INFO  net.spy.memcached.ConfigurationPoller - Endpoint to use for configuration access in this poll NodeEndPoint - HostName:COMPANY20-test.dcsnk0.0001.euw1.cache.amazonaws.com IpAddress:172.31.3.22 Port:11211

Apr 25, 2017 1:41:26 PM de.javakaffee.web.msm.MemcachedSessionService setLockingMode
INFO: Setting lockingMode to null
Apr 25, 2017 1:41:27 PM de.javakaffee.web.msm.MemcachedSessionService createTranscoderFactory
INFO: Creating transcoder factory de.javakaffee.web.msm.JavaSerializationTranscoderFactory
Apr 25, 2017 1:41:27 PM de.javakaffee.web.msm.MemcachedSessionService loadTranscoderFactoryClass
FINE: Loading transcoder factory class de.javakaffee.web.msm.JavaSerializationTranscoderFactory using classloader WebappClassLoader
  context: 
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
java.net.URLClassLoader@8b87145

Apr 25, 2017 1:41:27 PM de.javakaffee.web.msm.MemcachedSessionService startInternal
INFO: --------
-  finished initialization:
- sticky: true
- operation timeout: 1000
- node ids: []
- failover node ids: []
- storage key prefix: null
--------

Test: Empty JSESSION (new session):

FINE: createSession invoked: null
FINE: Created new session with id 03D0ED04219B077AA21C7DE4D68E5A01
FINE: Starting for session id 03D0ED04219B077AA21C7DE4D68E5A01

With JSESSIONID (03D0ED04219B077AA21C7DE4D68E5A01)

FINE: Loading session from memcached: 03D0ED04219B077AA21C7DE4D68E5A01
FINE: Session 03D0ED04219B077AA21C7DE4D68E5A01 not found in memcached.
FINE: No session found in session map for 03D0ED04219B077AA21C7DE4D68E5A01

Remarks:

  1. Using the regular session manager it works;
  2. Using one tomcat node only and sticky it works;
  3. Using two tomcat nodes and sticky doesn't work anymore;
  4. I also tried with the spymemcached libs instead of the amazon ones;
  5. Tried as well with tomcat8 (with the correct tc8 lib from memcached) but nothing as well;

Can someone please tell me where to fight my battle here? What could it be exactly?

rpvilao-gymondo avatar Apr 25 '17 14:04 rpvilao-gymondo

Sorry for the long delay! Several people reported issues with AWS. Can you get it running locally? This would show that the issues are not related to the app but related to the infrastructure.

magro avatar Jun 06 '17 23:06 magro

I am also facing same issue with the memcached .

  • I use in my Java Client spymemcached-2.12.3.jar , memcached-2.3.0.jar ,tc8-2.3.0.jar
  • When default Tomcat 8 session manager is used only 1 JSESSIONID is created in the page
  • When session manager changed to MemcachedBackupSessionManager and sticky is false it creates many JSESSIONID per page causing spring security unable to find authentication for current session as session ID is changed. So I am being logged out in my application.
  • I had issue with two tomcat nodes behind LB. sticky true and it was not able to find correct CSRF token as request is send to any of node in round robin.

Any suggestion ?

cpemaratech avatar Nov 23 '18 21:11 cpemaratech

@cpemaratech your setup is different to the one originally reported (no aws, different memcached client), right? In this case please submit a separate issue. If possible please provide a minimal sample project that allows to reproduce the issue.

magro avatar Nov 24 '18 13:11 magro