Skip to content

Comments

Fix Connection Close Exception Handling for commons-pool2 2.13.1#4439

Open
atakavci wants to merge 4 commits intoredis:masterfrom
atakavci:apacheCommonsPoolBehaviourChange
Open

Fix Connection Close Exception Handling for commons-pool2 2.13.1#4439
atakavci wants to merge 4 commits intoredis:masterfrom
atakavci:apacheCommonsPoolBehaviourChange

Conversation

@atakavci
Copy link
Contributor

Summary

Here the bump attempt for org.apache.commons:commons-pool2 from 2.12.1 to 2.13.1.
Those tests failing during connection close is due to behavioral change - the way invalidateObject tries addObject - in GenericObjectPools implementation.
This PR suppresses those exceptions during connection close to accommodate the behavioral change.

Context

Starting with commons-pool2 2.13.1, GenericObjectPool.invalidateObject() attempts to replace invalidated instances, which can fail when ConnectionFactory.makeObject() throws an exception. This change ensures the original exception is preserved while suppressing any secondary exceptions from connection cleanup.


⚠️ The version bump itself will also result propagating the behavioral change to Jedis users.. So it will be a breaking change for Jedis and i am not sure this is the right approach in this PR.
I am willing to follow up with the commons-pool team to explore whether a built-in option or a solution can be introduced in the pool implementation. Will update here any progress with commons-pool team.


Changes

  • Refactored MultiDbCommandExecutor.handleExecuteCommand() to properly suppress exceptions during connection.close()
  • Added closeAndSuppress() helper to capture initial exceptions and suppress close-time exceptions
  • Updated UnavailableConnectionTest to handle expected exception from pool invalidation

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts Jedis’ connection-close error handling to accommodate a behavior change in commons-pool2 2.13.1 where GenericObjectPool.invalidateObject() attempts to create a replacement instance, potentially throwing a secondary exception during cleanup.

Changes:

  • Refactors MultiDbCommandExecutor.handleExecuteCommand() to preserve the original command exception while suppressing close-time exceptions.
  • Adds helper methods (acquireConnection, isFailDuringFailover, closeAndSuppress) to structure the new close/suppression behavior.
  • Updates UnavailableConnectionTest to tolerate the new pool invalidation behavior during close().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/main/java/redis/clients/jedis/mcf/MultiDbCommandExecutor.java Adds close-time exception suppression so command failures are not replaced by cleanup failures.
src/test/java/redis/clients/jedis/UnavailableConnectionTest.java Adjusts integration test expectations around close() under the new pool invalidation semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant