Skip to content

Commit

Permalink
Synchronize on saveMonitor until output is closed and done
Browse files Browse the repository at this point in the history
The persistent files are not finalized until we close the
output stream to allow the ManagedOutputStream to get everything
safely persisted into the final location on disk. We should
protect multiple threads from trying to do this final step
in persisting like we do for all the writes to the output
stream.
  • Loading branch information
tjwatson committed Mar 26, 2024
1 parent 26a567e commit af69dde
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1348,8 +1348,8 @@ void save0() throws IOException {
DataOutputStream out = null;
boolean success = false;
moduleDatabase.readLock();
try {
synchronized (this.saveMonitor) {
synchronized (this.saveMonitor) {
try {
if (lastSavedTimestamp == moduleDatabase.getTimestamp())
return;
childStorageManager = getChildStorageManager();
Expand All @@ -1360,24 +1360,24 @@ void save0() throws IOException {
moduleDatabase.store(out, true);
lastSavedTimestamp = moduleDatabase.getTimestamp();
success = true;
}
} finally {
if (!success) {
if (mos != null) {
mos.abort();
} finally {
moduleDatabase.readUnlock();
if (!success) {
if (mos != null) {
mos.abort();
}
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
// tried our best
if (out != null) {
try {
out.close();
} catch (IOException e) {
// tried our best
}
}
if (childStorageManager != null) {
childStorageManager.close();
}
}
if (childStorageManager != null) {
childStorageManager.close();
}
moduleDatabase.readUnlock();
}
}

Expand Down

0 comments on commit af69dde

Please sign in to comment.