Repository navigation
Conversation
…ces. executeWithStickyConnection(…) obtains its connection via RedisConnectionUtils and increments the reference count of a connection bound to the current thread, for example within execute(SessionCallback). Cursors returned from SCAN commands closed the bound connection directly, so the session lost its connection and the reference count never dropped back to zero, leaving the closed connection bound to the thread. We now hand out a proxy for bound connections whose close(), and the close() of cursors obtained from it, releases the reference through RedisConnectionUtils.releaseConnection(…) instead of closing the bound connection. Closes spring-projects#2148 Signed-off-by: Sparshal Kothari <41056517+spor3006@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2148
Calling
scan()(oropsForSet/Hash/ZSet().scan()) insideexecute(SessionCallback)leaks the session's connection.executeWithStickyConnectionpicks up the connection bound to the thread and increments the holder's reference count, but the cursor later closes that connection directly instead of releasing the reference. The session ends up with a closed connection, the count never gets back to zero, and the holder stays bound to the thread.Following the feedback on #3457, this keeps using the bound connection and fixes the reference counting instead. When the sticky connection is the thread-bound one, the callback gets a proxy whose
close()goes throughRedisConnectionUtils.releaseConnection(…). Cursors returned from the proxy are wrapped so that closing them releases the reference the same way rather than closing the bound connection. The release happens at most once per sticky call. Without a bound connection nothing changes: the cursor closes its own connection as before.Cursors obtained through the command interfaces (e.g.
connection.keyCommands().scan(…)) in a customexecuteWithStickyConnectioncallback are not wrapped; all in-tree callers use the top-level methods. Happy to extend this if you prefer.Tests: new
RedisTemplateUnitTestscases with a mocked connection factory check that inside a session the bound connection is not closed by the cursor, is unbound fromTransactionSynchronizationManagerafter the session, and is closed exactly once; and that outside a session closing the cursor still closes the connection. Two of them fail on currentmain. The existingRedisTemplate,RedisConnectionUtils, cursor andDefault*Operationsunit tests pass.