Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cadc-vos-server: catch exceptions and close childIterator #235

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cadc-vos-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '2.0.13'
version = '2.0.14'

description = 'OpenCADC VOSpace server'
def git_url = 'https://github.com/opencadc/vos'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public void doAction() throws Exception {
}
log.debug("found: " + target + " as " + serverNode);

ResourceIterator<Node> resourceIter = null;
if (serverNode instanceof ContainerNode) {
ContainerNode node = (ContainerNode) serverNode;

Expand Down Expand Up @@ -192,7 +193,8 @@ public void doAction() throws Exception {

// Check for read permission to list child nodes.
Subject subject = AuthenticationUtil.getCurrentSubject();
if (voSpaceAuthorizer.hasSingleNodeReadPermission(node, subject)) {
if ((pageLimit == null || pageLimit > 0)
&& voSpaceAuthorizer.hasSingleNodeReadPermission(node, subject)) {
long start = System.currentTimeMillis();
log.debug(String.format("get children of %s: start=[%s] limit=[%s] detail=%s", target.getPath(), startURI, pageLimit, detailLevel));
try {
Expand All @@ -202,6 +204,7 @@ public void doAction() throws Exception {
} else {
node.childIterator = ci;
}
resourceIter = node.childIterator;
} catch (UnsupportedOperationException ex) {
throw NodeFault.OptionNotSupported.getStatus(ex.getMessage());
}
Expand Down Expand Up @@ -237,8 +240,18 @@ public void doAction() throws Exception {

syncOutput.setCode(200);
syncOutput.setHeader(HttpTransfer.CONTENT_TYPE, getMediaType());
// TODO: should the VOSURI in the output target or actual? eg resolveLinks=true
nodeWriter.write(localServiceURI.getURI(serverNode), serverNode, syncOutput.getOutputStream(), detail);
try {
nodeWriter.write(localServiceURI.getURI(serverNode), serverNode, syncOutput.getOutputStream(), detail);
} finally {
if (resourceIter != null) {
try {
resourceIter.close();
} catch (Exception failToClose) {
log.error("BADNESS: failed to close ContainerNode.childIterator -- possible resource leak", failToClose);

}
}
}
}

private class TagChildAccessRightsWrapper implements ResourceIterator<Node> {
Expand Down
2 changes: 1 addition & 1 deletion cavern/VERSION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## deployable containers have a semantic and build tag
# semantic version tag: major.minor
# build version tag: timestamp
VER=0.7.4
VER=0.7.5
TAGS="${VER} ${VER}-$(date -u +"%Y%m%dT%H%M%S")"
unset VER
2 changes: 1 addition & 1 deletion cavern/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
implementation 'org.opencadc:cadc-dali:[1.0,)'
implementation 'org.opencadc:cadc-pkg-server:[1.2.3,)'
implementation 'org.opencadc:cadc-vos:[2.0,)'
implementation 'org.opencadc:cadc-vos-server:[2.0.11,)'
implementation 'org.opencadc:cadc-vos-server:[2.0.14,)'

runtimeOnly 'org.opencadc:cadc-access-control-identity:[1.2.0,)'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public void close() throws IOException {
private class IdentWrapper implements ResourceIterator<Node> {

private final ContainerNode parent;
private final ResourceIterator<Node> childIter;
private ResourceIterator<Node> childIter;
private final NodeUtil nut;

IdentWrapper(ContainerNode parent, ResourceIterator<Node> childIter, NodeUtil nut) {
Expand Down Expand Up @@ -373,7 +373,11 @@ public Node next() {

@Override
public void close() throws IOException {
childIter.close();
if (childIter != null) {
// silently OK to close more than once
childIter.close();
childIter = null;
}
}
}

Expand Down
Loading