This is an automated email from the ASF dual-hosted git repository.
markt-asf 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 517596b11a Avoid concurrency issues with file save operations.
517596b11a is described below
commit 517596b11a98837f4a91b04decdb34866232dacc
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Jun 17 08:22:44 2026 +0100
Avoid concurrency issues with file save operations.
---
.../apache/catalina/users/MemoryUserDatabase.java | 54 +++++++++++-----------
webapps/docs/changelog.xml | 5 ++
2 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/java/org/apache/catalina/users/MemoryUserDatabase.java
b/java/org/apache/catalina/users/MemoryUserDatabase.java
index 58350383ce..4ae43c9c83 100644
--- a/java/org/apache/catalina/users/MemoryUserDatabase.java
+++ b/java/org/apache/catalina/users/MemoryUserDatabase.java
@@ -598,37 +598,37 @@ public class MemoryUserDatabase implements UserDatabase {
throw ioe;
}
this.lastModified = fileNew.lastModified();
- } finally {
- writeLock.unlock();
- }
- // Perform the required renames to permanently save this file
- File fileOld = new File(pathnameOld);
- if (!fileOld.isAbsolute()) {
- fileOld = new File(System.getProperty(Globals.CATALINA_BASE_PROP),
pathnameOld);
- }
- if (fileOld.exists() && !fileOld.delete()) {
- throw new
IOException(sm.getString("memoryUserDatabase.fileDelete", fileOld));
- }
- File fileOrig = new File(pathname);
- if (!fileOrig.isAbsolute()) {
- fileOrig = new
File(System.getProperty(Globals.CATALINA_BASE_PROP), pathname);
- }
- if (fileOrig.exists()) {
- if (!fileOrig.renameTo(fileOld)) {
- throw new
IOException(sm.getString("memoryUserDatabase.renameOld",
fileOld.getAbsolutePath()));
+ // Perform the required renames to permanently save this file
+ File fileOld = new File(pathnameOld);
+ if (!fileOld.isAbsolute()) {
+ fileOld = new
File(System.getProperty(Globals.CATALINA_BASE_PROP), pathnameOld);
}
- }
- if (!fileNew.renameTo(fileOrig)) {
- if (fileOld.exists()) {
- if (!fileOld.renameTo(fileOrig)) {
- log.warn(sm.getString("memoryUserDatabase.restoreOrig",
fileOld));
+ if (fileOld.exists() && !fileOld.delete()) {
+ throw new
IOException(sm.getString("memoryUserDatabase.fileDelete", fileOld));
+ }
+ File fileOrig = new File(pathname);
+ if (!fileOrig.isAbsolute()) {
+ fileOrig = new
File(System.getProperty(Globals.CATALINA_BASE_PROP), pathname);
+ }
+ if (fileOrig.exists()) {
+ if (!fileOrig.renameTo(fileOld)) {
+ throw new
IOException(sm.getString("memoryUserDatabase.renameOld",
fileOld.getAbsolutePath()));
}
}
- throw new IOException(sm.getString("memoryUserDatabase.renameNew",
fileOrig.getAbsolutePath()));
- }
- if (fileOld.exists() && !fileOld.delete()) {
- throw new
IOException(sm.getString("memoryUserDatabase.fileDelete", fileOld));
+ if (!fileNew.renameTo(fileOrig)) {
+ if (fileOld.exists()) {
+ if (!fileOld.renameTo(fileOrig)) {
+
log.warn(sm.getString("memoryUserDatabase.restoreOrig", fileOld));
+ }
+ }
+ throw new
IOException(sm.getString("memoryUserDatabase.renameNew",
fileOrig.getAbsolutePath()));
+ }
+ if (fileOld.exists() && !fileOld.delete()) {
+ throw new
IOException(sm.getString("memoryUserDatabase.fileDelete", fileOld));
+ }
+ } finally {
+ writeLock.unlock();
}
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 50fb6c24c0..f167aec9da 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -286,6 +286,11 @@
application. Empty sections are no longer logged. Special roles and
empty authorisation constraints are included. (markt)
</fix>
+ <fix>
+ Expand the write lock for the save process in the
+ <code>MemoryUserDatabase</code> to avoid concurrency issues with the
+ file save operations. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]