This is an automated email from the ASF dual-hosted git repository.
kfujino pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 33ec983 Fix race condition when saving and recycling session in
PersistentValve.
33ec983 is described below
commit 33ec983d8204d1c08610b83182d4412791970202
Author: KeiichiFujino <[email protected]>
AuthorDate: Tue Sep 15 22:35:58 2020 +0900
Fix race condition when saving and recycling session in PersistentValve.
---
.../apache/catalina/valves/PersistentValve.java | 29 +++++++++++-----------
webapps/docs/changelog.xml | 4 +++
2 files changed, 18 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 2493e7b..2a53152 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -51,6 +51,10 @@
The health check valve will now check the state of its associated
containers to report availability. (remm)
</update>
+ <fix>
+ Fix race condition when saving and recycling session in
+ <code>PersistentValve</code>. (kfujino)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]