Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion java/org/apache/catalina/session/FileStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,21 @@ public void save(Session session) throws IOException {
.trace(sm.getString(getStoreName() + ".saving", session.getIdInternal(), file.getAbsolutePath()));
}

File tempFile = new File(file.getAbsolutePath() + ".tmp");

Lock writeLock = sessionLocksById.getLock(session.getIdInternal()).writeLock();
writeLock.lock();
try {
try (FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
try (FileOutputStream fos = new FileOutputStream(tempFile);
ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(fos))) {
((StandardSession) session).writeObjectData(oos);
}
if (!tempFile.renameTo(file)) {
if (tempFile.exists() && !tempFile.delete()) {
log.warn(sm.getString("fileStore.deleteFailed", tempFile));
}
throw new IOException(sm.getString("fileStore.renameFailed", tempFile, file));
}
} finally {
writeLock.unlock();
}
Expand Down