This is an automated email from the ASF dual-hosted git repository.

kfujino pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
     new d14d690  Fix race condition when saving and recycling session in 
PersistentValve.
d14d690 is described below

commit d14d690144aa8250a36ab6aed37f50fdb1b4bddf
Author: KeiichiFujino <kfuj...@apache.org>
AuthorDate: Tue Sep 15 22:42:27 2020 +0900

    Fix race condition when saving and recycling session in PersistentValve.
---
 .../apache/catalina/valves/PersistentValve.java    | 29 +++++++++++-----------
 webapps/docs/changelog.xml                         |  8 ++++++
 2 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/java/org/apache/catalina/valves/PersistentValve.java 
b/java/org/apache/catalina/valves/PersistentValve.java
index 7734e26..df94820 100644
--- a/java/org/apache/catalina/valves/PersistentValve.java
+++ b/java/org/apache/catalina/valves/PersistentValve.java
@@ -170,22 +170,21 @@ public class PersistentValve extends ValveBase {
                     if (manager instanceof StoreManager) {
                         Session session = manager.findSession(newsessionId);
                         Store store = ((StoreManager) manager).getStore();
-                        if (store != null && session != null && 
session.isValid() &&
-                                !isSessionStale(session, 
System.currentTimeMillis())) {
-                            store.save(session);
-                            ((StoreManager) manager).removeSuper(session);
-                            session.recycle();
-                        } else {
-                            if (container.getLogger().isDebugEnabled()) {
-                                container.getLogger().debug("newsessionId 
store: " +
-                                        store + " session: " + session +
-                                        " valid: " +
-                                        (session == null ? "N/A" : 
Boolean.toString(
-                                                session.isValid())) +
-                                        " stale: " + isSessionStale(session,
-                                                System.currentTimeMillis()));
-                            }
+                        synchronized (session) {
+                            if (store != null && session != null && 
session.isValid()
+                                    && !isSessionStale(session, 
System.currentTimeMillis())) {
+                                store.save(session);
+                                ((StoreManager) manager).removeSuper(session);
+                                session.recycle();
+                            } else {
+                                if (container.getLogger().isDebugEnabled()) {
+                                    container.getLogger()
+                                            .debug("newsessionId store: " + 
store + " session: " + session + " valid: "
+                                                    + (session == null ? "N/A" 
: Boolean.toString(session.isValid()))
+                                                    + " stale: " + 
isSessionStale(session, System.currentTimeMillis()));
+                                }
 
+                            }
                         }
                     } else {
                         if (container.getLogger().isDebugEnabled()) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index f378ad6..328941f 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -45,6 +45,14 @@
   issues do not "pop up" wrt. others).
 -->
 <section name="Tomcat 8.5.59 (markt)" rtext="in development">
+  <subsection name="Catalina">
+    <changelog>
+      <fix>
+        Fix race condition when saving and recycling session in
+        <code>PersistentValve</code>. (kfujino)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Coyote">
     <changelog>
       <fix>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to