Skip to content

Commit

Permalink
datadir: fix unreleased lock on global.xml starting off an empt datadir
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
groldan committed May 1, 2024
1 parent 4dac461 commit 04a5cb4
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<GeoServerInfo> global = loadGlobalInfo();
final long initialValue = global.map(GeoServerInfo::getUpdateSequence).orElse(0L);
save(resource, initialValue);
}

private Optional<GeoServerInfo> 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() {
Expand Down

0 comments on commit 04a5cb4

Please sign in to comment.