Issue #4895 SessionCache flushOnResponseCommit with invalid session (#4896)

Signed-off-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
Jan Bartel 2020-05-20 23:05:53 +02:00 committed by GitHub
parent 3845790c5d
commit 52e7dd4873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -479,7 +479,7 @@ public abstract class AbstractSessionCache extends ContainerLifeCycle implements
{
//only write the session out at this point if the attributes changed. If only
//the lastAccess/expiry time changed defer the write until the last request exits
if (session.getSessionData().isDirty() && _flushOnResponseCommit)
if (session.isValid() && session.getSessionData().isDirty() && _flushOnResponseCommit)
{
if (LOG.isDebugEnabled())
LOG.debug("Flush session {} on response commit", session);

View File

@ -54,6 +54,7 @@ public class RemoveSessionTest
String servletMapping = "/server";
DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory();
cacheFactory.setFlushOnResponseCommit(true);
cacheFactory.setEvictionPolicy(SessionCache.NEVER_EVICT);
SessionDataStoreFactory storeFactory = new TestSessionDataStoreFactory();
@ -93,6 +94,9 @@ public class RemoveSessionTest
assertEquals(0, ((DefaultSessionCache)m.getSessionCache()).getSessionsCurrent());
assertEquals(1, ((DefaultSessionCache)m.getSessionCache()).getSessionsMax());
assertEquals(1, ((DefaultSessionCache)m.getSessionCache()).getSessionsTotal());
//check the session is no longer in the cache
assertFalse(((AbstractSessionCache)m.getSessionCache()).contains(TestServer.extractSessionId(sessionCookie)));
//check the session is not persisted any more
assertFalse(m.getSessionCache().getSessionDataStore().exists(TestServer.extractSessionId(sessionCookie)));
@ -125,7 +129,8 @@ public class RemoveSessionTest
String action = request.getParameter("action");
if ("create".equals(action))
{
request.getSession(true);
HttpSession s = request.getSession(true);
s.setAttribute("foo", "bar");
}
else if ("delete".equals(action))
{