Skip to content

Fix borrowObject timeout wrapping#3666

Merged
a-TODO-rov merged 6 commits intoredis:mainfrom
JiHongKim98:main
Feb 13, 2026
Merged

Fix borrowObject timeout wrapping#3666
a-TODO-rov merged 6 commits intoredis:mainfrom
JiHongKim98:main

Conversation

@JiHongKim98
Copy link
Copy Markdown
Contributor

@JiHongKim98 JiHongKim98 commented Feb 12, 2026

fix #3623

Override borrowObject(long borrowMaxWaitMillis) in GenericObjectPool to apply connection wrapping when borrowing with timeout. This ensures connections borrowed with timeout are properly returned to the pool when closed via try-with-resources.

Without this fix, borrowObject(timeout) returns unwrapped connections that don't auto-return to pool, causing connection leaks.

Make sure that:

  • You have read the contribution guidelines.
  • You have created a feature request first to discuss your contribution intent. Please reference the feature request ticket number in the pull request.
  • You applied code formatting rules using the mvn formatter:format target. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

Override borrowObject(long borrowMaxWaitMillis) in GenericObjectPool
to apply connection wrapping when borrowing with timeout. This ensures
connections borrowed with timeout are properly returned to the pool
when closed via try-with-resources.

Without this fix, borrowObject(timeout) returns unwrapped connections
that don't auto-return to pool, causing connection leaks.
@jit-ci
Copy link
Copy Markdown

jit-ci bot commented Feb 12, 2026

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

Copy link
Copy Markdown
Contributor

@a-TODO-rov a-TODO-rov left a comment

Choose a reason for hiding this comment

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

Hey, @JiHongKim98
Thanks for the help !
I see you've overridden borrowObject(long borrowMaxWaitMillis) , but didn't override borrowObject(final Duration borrowMaxWaitDuration) , which is currently the officially supported method. So for this i will put PR in request changes.
On a side note - did you think what will happen if the commons library introduce another overload of this method - borrowObject(final Instant borrowMax) for example. Probably we will still fail silently. So do you think there is some more general solution ?
I completely realize that adding another overload is not highly probable, but i would like to hear your thoughts on this.

@JiHongKim98
Copy link
Copy Markdown
Contributor Author

JiHongKim98 commented Feb 12, 2026

@a-TODO-rov Thank you for the review!

You're right - I'll add the Duration overload.

About your question: I thought about using dynamic proxy to handle future overloads automatically. But I think that would add overhead and make the code more complex.

For now, I think the best approach is to explicitly override each method that commons-pool provides. If you're concerned about silent failures when new overloads are added, we could also add a defensive test that validates all borrowObject methods are properly overridden using reflection.

What do you think about these approaches?

Thanks again for the thorough review!

Override borrowObject(Duration) in GenericObjectPool to apply connection
wrapping, ensuring connections borrowed with Duration timeout are properly
returned to pool when closed via try-with-resources.

Add integration test following the same pattern as borrowObject(long) test.
JiHongKim98 and others added 4 commits February 13, 2026 04:03
Rename borrowObject test methods to be more explicit:
- genericPoolShouldWorkWithBorrowObjectTimeout -> TimeoutMillis
- genericPoolShouldWorkWithBorrowObjectDuration -> TimeoutDuration

This makes it clearer which parameter type each test covers.
@a-TODO-rov
Copy link
Copy Markdown
Contributor

Thanks @JiHongKim98
Seems we needed to override just the Duration method, because the others are just delegating to it.
I will be merging that one.

@a-TODO-rov a-TODO-rov merged commit c37a247 into redis:main Feb 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConnectionPoolSupport provides no support for borrowObject with timeout

2 participants