From 3845790c5d24ea69b1724acd45fdf27a76321c0c Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 20 May 2020 10:47:23 +0200 Subject: [PATCH 1/2] Hpack optimizations If the dynamic table size is already 0, do not evictAll. Signed-off-by: Greg Wilkins --- .../eclipse/jetty/http2/hpack/HpackContext.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackContext.java b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackContext.java index ab587240876..5625b2c0cb9 100644 --- a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackContext.java +++ b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackContext.java @@ -395,12 +395,15 @@ public class HpackContext { if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] evictAll", HpackContext.this.hashCode())); - _fieldMap.clear(); - _nameMap.clear(); - _offset = 0; - _size = 0; - _dynamicTableSizeInBytes = 0; - Arrays.fill(_entries, null); + if (size() > 0) + { + _fieldMap.clear(); + _nameMap.clear(); + _offset = 0; + _size = 0; + _dynamicTableSizeInBytes = 0; + Arrays.fill(_entries, null); + } } } From 52e7dd487344283cd44922c61b702b38c3237fa6 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 20 May 2020 23:05:53 +0200 Subject: [PATCH 2/2] Issue #4895 SessionCache flushOnResponseCommit with invalid session (#4896) Signed-off-by: Jan Bartel --- .../eclipse/jetty/server/session/AbstractSessionCache.java | 2 +- .../eclipse/jetty/server/session/RemoveSessionTest.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java index 2029098e3f5..d684ad13dce 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java @@ -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); diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java index 31b94bf4c83..670060c3832 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java @@ -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)) {