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

SharedEntityManagerCreator does not handle all exceptions for stored proc output param retrieval #30160

Closed
giuseppemilicia opened this issue Mar 22, 2023 · 2 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: superseded An issue that has been superseded by another type: bug A general bug

Comments

@giuseppemilicia
Copy link
Contributor

giuseppemilicia commented Mar 22, 2023

Affects: Spring Boot 6.0.4

In the SharedEntityManagerCreator class, the following code block invokes getOutputParameterValue which can throw a HibernateException.

try {
Object key = entry.getKey();
if (key instanceof Integer number) {
entry.setValue(storedProc.getOutputParameterValue(number));
}
else {
entry.setValue(storedProc.getOutputParameterValue(key.toString()));
}
}
catch (IllegalArgumentException ex) {
entry.setValue(ex);
}

The problem is that the catch block only handles IllegalArgumentException.

This causes a connection leak in the HikariCP pool because the subsequent EntityManagerFactoryUtils.closeEntityManager(this.entityManager); line will never be executed, and the entity manager will never be closed.

A possible solution is to change the catch block to handle the more general Exception or RuntimeException instead of IllegalArgumentException.

@sbrannen sbrannen added in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug labels Mar 22, 2023
@sbrannen
Copy link
Member

I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference.

giuseppemilicia added a commit to giuseppemilicia/spring-framework that referenced this issue Mar 22, 2023
@sbrannen sbrannen self-assigned this Mar 22, 2023
@sbrannen sbrannen added this to the 6.0.8 milestone Mar 22, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.3.x labels Mar 22, 2023
@sbrannen sbrannen changed the title Connection leak in HikariCP due to unhandled stored procedure output parameter exception SharedEntityManagerCreator does not handle all exceptions for stored proc output param retrieval Mar 22, 2023
@sbrannen sbrannen removed this from the 6.0.8 milestone Mar 22, 2023
@sbrannen sbrannen added status: superseded An issue that has been superseded by another and removed status: backported An issue that has been backported to maintenance branches labels Mar 22, 2023
@sbrannen
Copy link
Member

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: superseded An issue that has been superseded by another type: bug A general bug
Projects
None yet
2 participants