Repository navigation
Improve performance - #9186
Improve performance#9186caleeli wants to merge 3 commits into
Conversation
PR SummaryMedium Risk Overview
Lifecycle hooks call Reviewed by Cursor Bugbot for commit 13d40b1. Bugbot is set up for automated code reviews on this repo. Configure here. |
| @@ -135,7 +181,14 @@ public function getOrCache(string $key, callable $callback): mixed | |||
| */ | |||
| public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool | |||
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: MEDIUM
Description: Security-setting saves advance the shared L1 epoch in SettingObserver::saving before the SQL update commits, and SettingCacheManager::set() later stores the committed model in Redis without advancing the epoch again. A concurrent Octane worker that calls Setting::byKey in that window syncs to the new epoch, misses Redis, loads the still-old row, and keeps it in its process-local L1. On later requests the epochs match, so syncEpoch leaves that map in place and the worker keeps enforcing the pre-commit value. This sticks for session-control.ip_restriction and session-control.device_restriction (Setting::configByKey on every web request), for session.lifetime (SettingsConfigRepository always reloads it through byKey), and for sso.default.login when package-auth is installed. password-policies.* read through config() is memoized in SettingsConfigRepository::$items after the first lookup, so that path is not what makes the epoch bug sticky.
Impact: After an admin tightens session IP/device restrictions, idle timeout, or the default SSO login, Octane workers that resolved that key between the pre-commit epoch bump and the post-commit cache fill keep applying the previous weaker policy on the public web stack until some later setting write bumps the epoch. Users who land on those workers bypass the updated session or login control. Winning the race is timing-dependent; once won, the stale L1 entry persists across requests because epoch equality is treated as proof the memory map matches Redis.
Remediation: Publish the epoch only after the committed setting is the value stored in Redis: move the bump from the saving() invalidate path to the post-commit set() (or a saved() hook) after put(). Do not let resolve() cache a loader result under an epoch that was already advanced for an uncommitted write; a put of the pre-commit row that lands after set() must not become the value later workers treat as current. Keep invalidation and the committed fill atomic so a concurrent byKey cannot repopulate L1 with the old row at the epoch set() just published.
| } catch (Throwable $e) { | ||
| Log::info('SettingMemoryCache: failed to read epoch: ' . $e->getMessage()); | ||
|
|
||
| return self::$localEpochs[self::currentTenantKey()] ?? 0; |
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: MEDIUM
Description: On a warm Octane worker, a failed Redis epoch read is reported as the worker's own local epoch. syncEpoch then treats L1 as fresh and login/session code keeps enforcing the last in-memory authentication settings for the rest of the outage.
Impact: A public login request or an authenticated session request on that worker keeps the last L1 values for 2FA, login-attempt limit, default SSO, IP/device session restrictions, and session lifetime, including a more permissive value than the database. Before this L1 layer, the settings Redis repository get threw on connection loss, so the read failed instead of being treated as fresh. The new catch adds trust of process-local auth policy when the freshness oracle is unavailable. Cold workers still fail closed: with no local epoch, the catch returns 0, null !== 0 clears L1, and the following repository get throws.
Remediation: Do not return the local epoch from a failed remote read. Rethrow so the setting read fails closed, or skip L1 and the Redis get for that request and call the DB loader. Clearing L1 alone is not enough: resolve() still calls cacheManager->get before the loader, and that get throws while Redis is down.
|
gproly
left a comment
There was a problem hiding this comment.
Finding — Setting memory cache can serve stale values outside Octane
beginRequest() runs only when Laravel Octane fires RequestTerminated. Traditional PHP workers (one process per request lifecycle without that listener) never reset the per-request sync flag, so the in-memory settings map is not checked against Redis again after the first access in that worker process.
Example: Worker process A loads Setting::byKey('primary-color') and keeps the value in memory. An administrator updates that setting on another server; the observer invalidates Redis and increments the shared epoch. The next HTTP request handled by worker A still returns the old color because epoch synchronization is skipped.
Expected: Each new HTTP request should re-check the shared epoch (or equivalent) and drop the in-memory map when it changes, on every deployment mode, not only under Octane.
Secondary risk: The same Setting model instance can be reused across requests on a long-lived worker; in-place changes on one request can affect the next without a database save.
…oved epoch synchronization and cache handling
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 13d40b1. Configure here.
| } | ||
| } else { | ||
| $this->writeStoreEntry($key, $value); | ||
| } |
There was a problem hiding this comment.
Stale resolve can overwrite Redis
High Severity
resolve() re-checks the epoch before writing Redis, but the write itself is not guarded. A concurrent saved()/set() can bump the epoch and publish a committed value in the gap between forceResyncEpoch() and writeStoreEntry(), so a loader that still holds a pre-commit row overwrites L2 under the new epoch. Later workers then hit that stale envelope and never go back to the database until the setting is saved again.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 13d40b1. Configure here.
| if (method_exists($settingCache, 'publishEpoch')) { | ||
| $settingCache->publishEpoch(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Epoch publish runs before commit
Medium Severity
The new saved() hook comments that it publishes the L1 epoch after the row is committed, but it listens to Eloquent saved without afterCommit. Inside a wrapping DB::transaction(), that still runs before commit, so concurrent byKey() loaders can refill Redis with the pre-commit row after the epoch bump.
Reviewed by Cursor Bugbot for commit 13d40b1. Configure here.
| self::$localEpochs[$tenantKey] = $newEpoch; | ||
| self::$epochUnreliable[$tenantKey] = false; | ||
| self::$syncedThisRequest[$tenantKey] = true; | ||
| } |
There was a problem hiding this comment.
Failed epoch bump marked reliable
Medium Severity
bumpEpoch() always sets epochUnreliable to false and syncedThisRequest to true, even when incrementRemoteEpoch() fails both INCR and SET. The publishing worker then treats L1/L2 as trustworthy although other workers never saw an epoch change and keep serving stale memory.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 13d40b1. Configure here.






Issue & Reproduction Steps
Describe the issue this ticket solves and describe how to reproduce the issue (please attach any fixtures used to reproduce the issue).
Solution
How to Test
Describe how to test that this solution works.
Related Tickets & Packages
Code Review Checklist