From 04a5cb417c4f4133174e5c3ebae93da2cd2b34e2 Mon Sep 17 00:00:00 2001 From: Gabriel Roldan Date: Wed, 1 May 2024 18:18:14 -0300 Subject: [PATCH] datadir: fix unreleased lock on global.xml starting off an empt datadir `DataDirectoryUpdateSequence` initializes `GeoServerInfo` if not present with a zero'ed `updateSequence`. In doing so, it was loading the `global.xml` through `Resource.in():InputStream`, which in turn automatically acquires a lock on the resource, but it was not closing it, which releases the lock. --- .../datadirectory/DataDirectoryUpdateSequence.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/DataDirectoryUpdateSequence.java b/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/DataDirectoryUpdateSequence.java index 8e6b8a6a0..8694d3542 100644 --- a/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/DataDirectoryUpdateSequence.java +++ b/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/DataDirectoryUpdateSequence.java @@ -176,18 +176,24 @@ protected Properties load(Resource resource) throws IOException { /** Precondition: be called while holding the {@link #lock()} */ private void initialize(Resource resource) throws IOException { + Optional global = loadGlobalInfo(); + final long initialValue = global.map(GeoServerInfo::getUpdateSequence).orElse(0L); + save(resource, initialValue); + } + + private Optional loadGlobalInfo() throws IOException { GeoServerInfo geoServerInfo = null; if (null == geoServer) { Resource configResource = dd.config(new GeoServerInfoImpl()); if (Resources.exists(configResource)) { - geoServerInfo = persister().load(configResource.in(), GeoServerInfo.class); + byte[] contents = configResource.getContents(); + ByteArrayInputStream in = new ByteArrayInputStream(contents); + geoServerInfo = persister().load(in, GeoServerInfo.class); } } else { geoServerInfo = geoServer.getGlobal(); } - final long initialValue = - Optional.ofNullable(geoServerInfo).map(GeoServerInfo::getUpdateSequence).orElse(0L); - save(resource, initialValue); + return Optional.ofNullable(geoServerInfo); } protected Resource resource() {