-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[10.x] Prevent DB Cache::get()
occur race condition
#49031
Merged
taylorotwell
merged 14 commits into
laravel:10.x
from
xdevor:prevent-cache-get-occur-race-condition
Nov 17, 2023
Merged
[10.x] Prevent DB Cache::get()
occur race condition
#49031
taylorotwell
merged 14 commits into
laravel:10.x
from
xdevor:prevent-cache-get-occur-race-condition
Nov 17, 2023
Conversation
This file contains 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
…o prevent-cache-get-occur-race-condition
renovate bot
referenced
this pull request
in RadioRoster/backend
Nov 24, 2023
[![Mend Renovate logo banner](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [laravel/framework](https://laravel.com) ([source](https://togithub.com/laravel/framework)) | `10.30.1` -> `10.33.0` | [![age](https://developer.mend.io/api/mc/badges/age/packagist/laravel%2fframework/10.33.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/packagist/laravel%2fframework/10.33.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/packagist/laravel%2fframework/10.30.1/10.33.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/packagist/laravel%2fframework/10.30.1/10.33.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>laravel/framework (laravel/framework)</summary> ### [`v10.33.0`](https://togithub.com/laravel/framework/blob/HEAD/CHANGELOG.md#v10330---2023-11-21) [Compare Source](https://togithub.com/laravel/framework/compare/v10.32.1...v10.33.0) - \[10.x] Fix wrong parameter passing and add these rules to dependent rules by [@​kayw-geek](https://togithub.com/kayw-geek) in [https://github.com/laravel/framework/pull/49008](https://togithub.com/laravel/framework/pull/49008) - \[10.x] Make Validator::getValue() public by [@​shinsenter](https://togithub.com/shinsenter) in [https://github.com/laravel/framework/pull/49007](https://togithub.com/laravel/framework/pull/49007) - \[10.x] Custom messages for `Password` validation rule by [@​rcknr](https://togithub.com/rcknr) in [https://github.com/laravel/framework/pull/48928](https://togithub.com/laravel/framework/pull/48928) - \[10.x] Round milliseconds in database seeder console output runtime by [@​SjorsO](https://togithub.com/SjorsO) in [https://github.com/laravel/framework/pull/49014](https://togithub.com/laravel/framework/pull/49014) - \[10.x] Add a `Number` utility class by [@​caendesilva](https://togithub.com/caendesilva) in [https://github.com/laravel/framework/pull/48845](https://togithub.com/laravel/framework/pull/48845) - \[10.x] Fix the replace() method in DefaultService class by [@​jonagoldman](https://togithub.com/jonagoldman) in [https://github.com/laravel/framework/pull/49022](https://togithub.com/laravel/framework/pull/49022) - \[10.x] Pass the property $validator as a parameter to the $callback Closure by [@​shinsenter](https://togithub.com/shinsenter) in [https://github.com/laravel/framework/pull/49015](https://togithub.com/laravel/framework/pull/49015) - \[10.x] Fix Cache DatabaseStore::add() error occur on Postgres within transaction by [@​xdevor](https://togithub.com/xdevor) in [https://github.com/laravel/framework/pull/49025](https://togithub.com/laravel/framework/pull/49025) - \[10.x] Support asserting against chained batches by [@​taylorotwell](https://togithub.com/taylorotwell) in [https://github.com/laravel/framework/pull/49003](https://togithub.com/laravel/framework/pull/49003) - \[10.x] Prevent DB `Cache::get()` occur race condition by [@​xdevor](https://togithub.com/xdevor) in [https://github.com/laravel/framework/pull/49031](https://togithub.com/laravel/framework/pull/49031) - \[10.x] Fix notifications being counted as sent without a "shouldSend" method by [@​joelwmale](https://togithub.com/joelwmale) in [https://github.com/laravel/framework/pull/49030](https://togithub.com/laravel/framework/pull/49030) - \[10.x] Fix tests failure on Windows by [@​hafezdivandari](https://togithub.com/hafezdivandari) in [https://github.com/laravel/framework/pull/49037](https://togithub.com/laravel/framework/pull/49037) - \[10.x] Add unless conditional on validation rules by [@​michaelnabil230](https://togithub.com/michaelnabil230) in [https://github.com/laravel/framework/pull/49048](https://togithub.com/laravel/framework/pull/49048) - \[10.x] Handle string based payloads that are not JSON or form data when creating PSR request instances by [@​timacdonald](https://togithub.com/timacdonald) in [https://github.com/laravel/framework/pull/49047](https://togithub.com/laravel/framework/pull/49047) - \[10.x] Fix directory separator CMD display on windows by [@​imanghafoori1](https://togithub.com/imanghafoori1) in [https://github.com/laravel/framework/pull/49045](https://togithub.com/laravel/framework/pull/49045) - \[10.x] Fix mapSpread doc by [@​timacdonald](https://togithub.com/timacdonald) in [https://github.com/laravel/framework/pull/48941](https://togithub.com/laravel/framework/pull/48941) - \[10.x] Tiny `Support\Collection` test fix - Unused data provider parameter by [@​stevebauman](https://togithub.com/stevebauman) in [https://github.com/laravel/framework/pull/49053](https://togithub.com/laravel/framework/pull/49053) - \[10.x] Feat: Add color_hex validation rule by [@​nikopeikrishvili](https://togithub.com/nikopeikrishvili) in [https://github.com/laravel/framework/pull/49056](https://togithub.com/laravel/framework/pull/49056) - \[10.x] Handle missing translation strings using callback by [@​DeanWunder](https://togithub.com/DeanWunder) in [https://github.com/laravel/framework/pull/49040](https://togithub.com/laravel/framework/pull/49040) - \[10.x] Add Str::transliterate to Stringable by [@​dwightwatson](https://togithub.com/dwightwatson) in [https://github.com/laravel/framework/pull/49065](https://togithub.com/laravel/framework/pull/49065) - Add Alpha Channel support to Hex validation rule by [@​ahinkle](https://togithub.com/ahinkle) in [https://github.com/laravel/framework/pull/49069](https://togithub.com/laravel/framework/pull/49069) ### [`v10.32.1`](https://togithub.com/laravel/framework/blob/HEAD/CHANGELOG.md#v10321---2023-11-14) [Compare Source](https://togithub.com/laravel/framework/compare/v10.32.0...v10.32.1) - \[10.x] Add `[@pushElseIf](https://togithub.com/pushElseIf)` and `[@pushElse](https://togithub.com/pushElse)` by [@​jasonmccreary](https://togithub.com/jasonmccreary) in [https://github.com/laravel/framework/pull/48990](https://togithub.com/laravel/framework/pull/48990) ### [`v10.32.0`](https://togithub.com/laravel/framework/blob/HEAD/CHANGELOG.md#v10320---2023-11-14) [Compare Source](https://togithub.com/laravel/framework/compare/v10.31.0...v10.32.0) - Update PendingRequest.php by [@​mattkingshott](https://togithub.com/mattkingshott) in [https://github.com/laravel/framework/pull/48939](https://togithub.com/laravel/framework/pull/48939) - \[10.x] Change array_key_exists with null coalescing assignment operator in FilesystemAdapter by [@​miladev95](https://togithub.com/miladev95) in [https://github.com/laravel/framework/pull/48943](https://togithub.com/laravel/framework/pull/48943) - \[10.x] Use container to resolve email validator class by [@​orkhanahmadov](https://togithub.com/orkhanahmadov) in [https://github.com/laravel/framework/pull/48942](https://togithub.com/laravel/framework/pull/48942) - \[10.x] Added `getGlobalMiddleware` method to HTTP Client Factory by [@​pascalbaljet](https://togithub.com/pascalbaljet) in [https://github.com/laravel/framework/pull/48950](https://togithub.com/laravel/framework/pull/48950) - \[10.x] Detect MySQL read-only mode error as a lost connection by [@​cosmastech](https://togithub.com/cosmastech) in [https://github.com/laravel/framework/pull/48937](https://togithub.com/laravel/framework/pull/48937) - \[10.x] Adds more implicit validation rules for `present` based on other fields by [@​diamondobama](https://togithub.com/diamondobama) in [https://github.com/laravel/framework/pull/48908](https://togithub.com/laravel/framework/pull/48908) - \[10.x] Refactor set_error_handler callback to use arrow function in `InteractsWithDeprecationHandling` by [@​miladev95](https://togithub.com/miladev95) in [https://github.com/laravel/framework/pull/48954](https://togithub.com/laravel/framework/pull/48954) - \[10.x] Test Improvements by [@​crynobone](https://togithub.com/crynobone) in [https://github.com/laravel/framework/pull/48962](https://togithub.com/laravel/framework/pull/48962) - Fix issue that prevents BladeCompiler to raise an exception when temporal compiled blade template is not found. by [@​juanparati](https://togithub.com/juanparati) in [https://github.com/laravel/framework/pull/48957](https://togithub.com/laravel/framework/pull/48957) - \[10.x] Fix how nested transaction callbacks are handled by [@​mateusjatenee](https://togithub.com/mateusjatenee) in [https://github.com/laravel/framework/pull/48859](https://togithub.com/laravel/framework/pull/48859) - \[10.x] Fixes Batch Callbacks not triggering if job timeout while in transaction by [@​crynobone](https://togithub.com/crynobone) in [https://github.com/laravel/framework/pull/48961](https://togithub.com/laravel/framework/pull/48961) - \[10.x] expressions in migration computations fail by [@​tpetry](https://togithub.com/tpetry) in [https://github.com/laravel/framework/pull/48976](https://togithub.com/laravel/framework/pull/48976) - \[10.x] Fixes Exception: Cannot traverse an already closed generator when running Arr::first with an empty generator and no callback by [@​moshe-autoleadstar](https://togithub.com/moshe-autoleadstar) in [https://github.com/laravel/framework/pull/48979](https://togithub.com/laravel/framework/pull/48979) - fixes issue with stderr when there was "]" character. by [@​nikopeikrishvili](https://togithub.com/nikopeikrishvili) in [https://github.com/laravel/framework/pull/48975](https://togithub.com/laravel/framework/pull/48975) - \[10.x] Fix Postgres cache store failed to put exist cache in transaction by [@​xdevor](https://togithub.com/xdevor) in [https://github.com/laravel/framework/pull/48968](https://togithub.com/laravel/framework/pull/48968) ### [`v10.31.0`](https://togithub.com/laravel/framework/blob/HEAD/CHANGELOG.md#v10310---2023-11-07) [Compare Source](https://togithub.com/laravel/framework/compare/v10.30.1...v10.31.0) - \[10.x] Allow `Sleep::until()` to be passed a timestamp as a string by [@​jameshulse](https://togithub.com/jameshulse) in [https://github.com/laravel/framework/pull/48883](https://togithub.com/laravel/framework/pull/48883) - \[10.x] Fix whereHasMorph() with nullable morphs by [@​MarkKremer](https://togithub.com/MarkKremer) in [https://github.com/laravel/framework/pull/48903](https://togithub.com/laravel/framework/pull/48903) - \[10.x] Handle `class_parents` returning false in `class_uses_recursive` by [@​RoflCopter24](https://togithub.com/RoflCopter24) in [https://github.com/laravel/framework/pull/48902](https://togithub.com/laravel/framework/pull/48902) - \[10.x] Enable default retrieval of all fragments in `fragments()` and `fragmentsIf()` methods by [@​tabuna](https://togithub.com/tabuna) in [https://github.com/laravel/framework/pull/48894](https://togithub.com/laravel/framework/pull/48894) - \[10.x] Allow placing a batch on a chain by [@​khepin](https://togithub.com/khepin) in [https://github.com/laravel/framework/pull/48633](https://togithub.com/laravel/framework/pull/48633) - \[10.x] Dispatch 'connection failed' event in async http client request by [@​gdebrauwer](https://togithub.com/gdebrauwer) in [https://github.com/laravel/framework/pull/48900](https://togithub.com/laravel/framework/pull/48900) - authenticate method refactored to use null coalescing operator by [@​miladev95](https://togithub.com/miladev95) in [https://github.com/laravel/framework/pull/48917](https://togithub.com/laravel/framework/pull/48917) - \[10.x] Add support for Sec-Purpose header by [@​nanos](https://togithub.com/nanos) in [https://github.com/laravel/framework/pull/48925](https://togithub.com/laravel/framework/pull/48925) - \[10.x] Allow setting retain_visibility config option on Flysystem filesystems by [@​jnoordsij](https://togithub.com/jnoordsij) in [https://github.com/laravel/framework/pull/48935](https://togithub.com/laravel/framework/pull/48935) - \[10.x] Escape forward slashes when exploding wildcard rules by [@​matt-farrugia](https://togithub.com/matt-farrugia) in [https://github.com/laravel/framework/pull/48936](https://togithub.com/laravel/framework/pull/48936) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/Lapotor/RadioRoster-api). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy41OS44IiwidXBkYXRlZEluVmVyIjoiMzcuNTkuOCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.
Problem I
Database
Cache::get()
will delete expired cache record automatically, but the current implementation may occur race condition, for example:imagine there're two process run parallell
Cache::get()
Cache:put()
if pA get a expired cache from DB but the deletion hasn't been executed yet, then pB
put()
a new cache record to DB, later when pA executeforget()
it will delete the new cache which put from pB.Solution
call
forgetIfExpired()
instead offorget()
inCache::get()
Problem II
When i write integration tests for this pull request, I found that
current DB
Cache::add()
has a bug from this PR (I'm sorry 😢),in
add()
method the$key
which pass toget()
already concat prefix andget()
will concat prefix again it self so the result will be wrongSolution
pass
$noPrefixKey
toget()
onCache::add()