Add try-with-resources to methods to insert BLOB#1654
Add try-with-resources to methods to insert BLOB#1654eleftherias merged 2 commits intospring-projects:masterfrom
Conversation
rwinch
left a comment
There was a problem hiding this comment.
Thanks for the PR! Can you please add some tests for the changes?
|
Hi @rwinch , Thank you for your reviewing. |
|
I'm guessing you could add a unit test to ensure that the temporary LOG is freed? |
|
Some test methods in |
|
I think you would need to verify that the lob that was created (which would be a mock also) is then closed proeprly. |
|
I am sure that freeing temporary LOB cannot be tested. If not using Oracle DB, we need to test if |
|
Do you believe it is possible? If yes, could you give me some more specific advice? |
|
I think it should be possible by injecting a mock LobHandler that returns a mock LobCreator. Then you would verify the LobCreator is closed. |
|
Thank you for your advice. I added a test method. Is this what you intended? |
|
@k-tamura Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
|
@k-tamura Thank you for signing the Contributor License Agreement! |
|
It would be very helpful if you could comment my test case. I added it on 22 Jul. Best regards, |
|
How's the review going? |
|
We are already in the release process. Given this is a bug, we can get it in the next patch release (Dec 9th). That will be in time for Spring Boot's GA release. |
|
Thanks for the PR @k-tamura! This is merged into master. |
|
Thank you! |

Problem
If using Oracle DB as a session store of Spring Session and idle connection timeout is not set (or connections do not become idle for a long time), there is a possibility that Oracle's TEMP space is increased and finally
SQLException(ORA-01652) is thrown.Note: This problem has already reported on #1321.
Description
When inserting a record to
SPRING_SESSION_ATTRIBUTEStable (which has Blob column), the following steps are executed:SPRING_SESSION_ATTRIBUTEStableThe created temporary LOB is freed when the connection (which created the temporary LOB) is closed by idle timeout or Spring application is restarted, but these events do not always occur.
Solution
So the following step should be added just after step 2.
To achieve this, try-with-resources statement should be added.
This problem is caused by leaks of calling
TemporaryLobCreator.close().TemporaryLobCreatorimplementsLobCreator(which extendsCloseable) and hasclose()(which frees temporary LOB), butTemporaryLobCreatoris created without try-with-resources statement. Thereforclose()is not called and temporary LOB is not freed.Steps to reproduce:
If you keep accessing to the application,
ORA-01652occurs andSQLExceptionis thrown.Result before applying my commit (CACHE_LOBS will increase):
Result after applying my commit (CACHE_LOBS will not increase):