From af69dde6494e13a2d81b845c3ba24f743975b631 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Tue, 26 Mar 2024 13:33:54 -0500 Subject: [PATCH] Synchronize on saveMonitor until output is closed and done 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. --- .../src/org/eclipse/osgi/storage/Storage.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java index cebb04624e5..0287089e43d 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java @@ -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(); @@ -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(); } }