diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java b/java/org/apache/catalina/connector/CoyoteAdapter.java index 7dfb4c0c2..e03d99072 100644 --- a/java/org/apache/catalina/connector/CoyoteAdapter.java +++ b/java/org/apache/catalina/connector/CoyoteAdapter.java @@ -939,9 +939,11 @@ protected boolean postParseRequest(org.apache.coyote.Request req, Request reques // Reset mapping request.getMappingData().recycle(); mapRequired = true; - // Recycle cookies in case correct context is - // configured with different settings + // Recycle cookies and session info in case the + // correct context is configured with different + // settings req.getCookies().recycle(); + request.recycleSessionInfo(); } break; } diff --git a/java/org/apache/catalina/connector/Request.java b/java/org/apache/catalina/connector/Request.java index ed061c280..f3c75f2f7 100644 --- a/java/org/apache/catalina/connector/Request.java +++ b/java/org/apache/catalina/connector/Request.java @@ -491,18 +491,7 @@ public void recycle() { notes.clear(); cookies = null; - if (session != null) { - try { - session.endAccess(); - } catch (Throwable t) { - ExceptionUtils.handleThrowable(t); - log.warn(sm.getString("coyoteRequest.sessionEndAccessFail"), t); - } - } - session = null; - requestedSessionCookie = false; - requestedSessionId = null; - requestedSessionURL = false; + recycleSessionInfo(); if (Globals.IS_SECURITY_ENABLED || Connector.RECYCLE_FACADES) { parameterMap = new ParameterMap<>(); @@ -545,11 +534,24 @@ public void clearEncoders() { } - /** - * Clear cached encoders (to save memory for Comet requests). - */ - public boolean read() - throws IOException { + protected void recycleSessionInfo() { + if (session != null) { + try { + session.endAccess(); + } catch (Throwable t) { + ExceptionUtils.handleThrowable(t); + log.warn(sm.getString("coyoteRequest.sessionEndAccessFail"), t); + } + } + session = null; + requestedSessionCookie = false; + requestedSessionId = null; + requestedSessionURL = false; + requestedSessionSSL = false; + } + + + public boolean read() throws IOException { return (inputBuffer.realReadBytes(null, 0, 0) > 0); } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index c43607854..ff4659366 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -157,6 +157,10 @@ 58582: Combined realm should perform background processing on its sub-realms. Based upon a patch provided by Aidan. (schultz) + + Handle the unlikely case where different versions of a web application + are deployed with different session settings. (markt) +