Skip to content

Commit

Permalink
GH-4968: server-spring - Close query result on pre-render exception (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad committed May 21, 2024
2 parents d878c68 + f9ed099 commit 4626eec
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public ModelAndView handleQueryRequest(HttpServletRequest request, RequestMethod
HttpServletResponse response) throws HTTPException, IOException {

RepositoryConnection repositoryCon = null;
Object queryResponse = null;

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

try {

Object queryResponse;

if (headersOnly) {
queryResponse = null;
} else {
Expand Down Expand Up @@ -114,10 +112,22 @@ public ModelAndView handleQueryRequest(HttpServletRequest request, RequestMethod
}

} catch (Exception e) {
// only close the connection when an exception occurs. Otherwise, the QueryResultView will take care of
// closing it.
if (repositoryCon != null) {
repositoryCon.close();
// only close the response & connection when an exception occurs. Otherwise, the QueryResultView will take
// care of closing it.
try {
if (queryResponse instanceof AutoCloseable) {
((AutoCloseable) queryResponse).close();
}
} catch (Exception qre) {
logger.warn("Query response closing error", qre);
} finally {
try {
if (repositoryCon != null) {
repositoryCon.close();
}
} catch (Exception qre) {
logger.warn("Connection closing error", qre);
}
}
throw e;
}
Expand Down

0 comments on commit 4626eec

Please sign in to comment.