Skip to content

Commit 4626eec

Browse files
authored
GH-4968: server-spring - Close query result on pre-render exception (#4969)
2 parents d878c68 + f9ed099 commit 4626eec

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

tools/server-spring/src/main/java/org/eclipse/rdf4j/http/server/repository/handler/AbstractQueryRequestHandler.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public ModelAndView handleQueryRequest(HttpServletRequest request, RequestMethod
5858
HttpServletResponse response) throws HTTPException, IOException {
5959

6060
RepositoryConnection repositoryCon = null;
61+
Object queryResponse = null;
6162

6263
try {
6364
Repository repository = repositoryResolver.getRepository(request);
@@ -75,9 +76,6 @@ public ModelAndView handleQueryRequest(HttpServletRequest request, RequestMethod
7576
boolean distinct = isDistinct(request);
7677

7778
try {
78-
79-
Object queryResponse;
80-
8179
if (headersOnly) {
8280
queryResponse = null;
8381
} else {
@@ -114,10 +112,22 @@ public ModelAndView handleQueryRequest(HttpServletRequest request, RequestMethod
114112
}
115113

116114
} catch (Exception e) {
117-
// only close the connection when an exception occurs. Otherwise, the QueryResultView will take care of
118-
// closing it.
119-
if (repositoryCon != null) {
120-
repositoryCon.close();
115+
// only close the response & connection when an exception occurs. Otherwise, the QueryResultView will take
116+
// care of closing it.
117+
try {
118+
if (queryResponse instanceof AutoCloseable) {
119+
((AutoCloseable) queryResponse).close();
120+
}
121+
} catch (Exception qre) {
122+
logger.warn("Query response closing error", qre);
123+
} finally {
124+
try {
125+
if (repositoryCon != null) {
126+
repositoryCon.close();
127+
}
128+
} catch (Exception qre) {
129+
logger.warn("Connection closing error", qre);
130+
}
121131
}
122132
throw e;
123133
}

0 commit comments

Comments
 (0)