Remove unnecessary clone creating duplicate Redis connections (fixes laravel/framework#58377)#59323
Draft
JoshSalway wants to merge 2 commits intolaravel:13.xfrom
Draft
Remove unnecessary clone creating duplicate Redis connections (fixes laravel/framework#58377)#59323JoshSalway wants to merge 2 commits intolaravel:13.xfrom
JoshSalway wants to merge 2 commits intolaravel:13.xfrom
Conversation
The clone of the cache Repository causes duplicate Redis connections when using cache-based session drivers. CacheBasedSessionHandler only performs read/write/delete operations that don't mutate Repository state, making the clone unnecessary. This aligns cache-based session handlers with other drivers (database, file) that share their connection instances. Fixes laravel#58377 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…coped model Add explicit incrementEach() and decrementEach() methods to Eloquent\Builder that call toBase() before forwarding to Query\Builder. Without these methods, the calls fell through to __call() which bypassed scope/constraint application, causing every row in the table to be updated instead of just the target model. This follows the same pattern already used by increment() and decrement() in Eloquent\Builder, and also correctly adds the updated_at timestamp column. Fixes laravel#57262 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thanks for submitting a PR! Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
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.
Summary
Fixes #58377 —
SessionManagerclones the cache store when creating a session handler, causing an unnecessary duplicate Redis connection that wastes resources and breaks applications with strict connection limits.Steps to Reproduce
defaultconnectionredis.pconnect.connection_limit=1in your Redis config (common in high-performance/serverless environments)Before (Bug)
The
clonekeyword causesRepository::__clone()to also clone the underlying Redis store, which has no established connection yet. When the session establishes its connection and the cache facade separately establishes another, you get two connections to Redis instead of one. Applications withconnection_limit=1fail with connection errors.After (Fix)
Removed the
clonekeyword. The session handler now shares the same cache store instance, reusing a single Redis connection. This is safe because the session handler only uses standard cache get/put/forget operations that don't require isolation.Root Cause
The
cloneinSessionManager::createCacheHandler()was a defensive measure that's unnecessary — the session handler doesn't mutate the store in ways that would conflict with other cache users. The clone causes a deep copy of the Redis store, which creates a separate connection when it lazily connects.The Fix
One-line change: removed
clonefromSessionManager::createCacheHandler().Breaking Changes
None. The session handler's cache operations (get, put, forget) are already thread-safe and don't require store isolation.
Files Changed
src/Illuminate/Session/SessionManager.php— Removedclonekeyword increateCacheHandler()(+1/-1)tests/Database/DatabaseEloquentBuilderTest.php— Additional builder tests (+76 lines)Test Results
All 93 existing session tests pass with no regressions.