8000 Fix Connection Close Exception Handling for commons-pool2 2.13.1 by atakavci · Pull Request #4439 · redis/jedis · GitHub
[go: up one dir, main page]

Skip to content

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

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

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

Conversation

@atakavci
Copy link
Contributor
@atakavci atakavci commented Feb 20, 2026

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

Note

Medium Risk
Touches core command execution/exception propagation and connection lifecycle; behavior changes could affect which exceptions callers observe and how failover errors are reported.

Overview
Prevents connection.close() failures (introduced by commons-pool2 2.13.1 invalidation behavior) from masking the original Redis command error in MultiDbCommandExecutor by capturing the command exception, suppressing any close-time exception onto it, and rethrowing the original (wrapping non-runtime in JedisException).

Refactors command execution to separate acquireConnection, failover-specific exception wrapping (ConnectionFailoverException), and the new closeConnectionAndRethrow path, and updates UnavailableConnectionTest to tolerate/validate the expected JedisException thrown on closing a broken resource.

Written by Cursor Bugbot for commit a7cbcac. This will update automatically on new commits. Configure here.

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.

8000

@ggivo ggivo added the breakingchange Pull request that has breaking changes. Must include the breaking behavior in release notes. label Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breakingchange Pull request that has breaking changes. Must include the breaking behavior in release notes. maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0