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

GH-4968: server-spring - Close query result on pre-render exception #4969

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: I thought it might be sensible here to log the result-close failure so the client still receives the original failure reason. Is that the right approach? And: Would it make sense to do the same for repositoryCon below?

Copy link
Contributor Author

@vtermanis vtermanis May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} finally {
try {
if (repositoryCon != null) {
repositoryCon.close();
}
} catch (Exception qre) {
logger.warn("Connection closing error", qre);
}
}
throw e;
}
Expand Down