Skip to content
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

Race Condition: dispatch() saves uncommitted models to async queue #29710

Closed
4n70w4 opened this issue Aug 23, 2019 · 3 comments
Closed

Race Condition: dispatch() saves uncommitted models to async queue #29710

4n70w4 opened this issue Aug 23, 2019 · 3 comments

Comments

@4n70w4
Copy link
Contributor

4n70w4 commented Aug 23, 2019

  • Laravel Version: 5.8.33
  • PHP Version: 7.3.8
  • Database Driver & Version: mysql

Description:

Job handler (horizon for example) throws ModelNotFoundException.
Because serialized models was recently created in parallel process but still don't commited (it's not about rollback).

Steps To Reproduce:

Create listener for saved (or another) model event with:

dispatch(new SomeJob($UncommitedModel) );

I see the simplest solution - dispatch() should throw an exception if the models are not commited.

Also implement something like dispatch_on_commit() which will dispatch only after a successful commit of the models necessary for serializing the job.

See also: laravel/ideas#1441

@4n70w4 4n70w4 changed the title Race Condition: dispatch() saves to async queue uncommited modes Race Condition: dispatch() saves to async queue uncommited models Aug 23, 2019
@4n70w4 4n70w4 changed the title Race Condition: dispatch() saves to async queue uncommited models Race Condition: dispatch() saves uncommitted models to async queue Aug 23, 2019
@mfn
Copy link
Contributor

mfn commented Aug 24, 2019

It's just a coincidence, but I updated it with a comment about a package which supports "transactional events", please see laravel/ideas#1441 (comment)

Here's btw an older issue talking about this problem: #8627 (there are likely more)

@driesvints
Copy link
Member

I think it's best that we stick this with the ideas issue. Feel free to submit a pr if you think this can be improved.

@mfn
Copy link
Contributor

mfn commented Jun 17, 2020

Hello everyone,

based on an existing package and with permission of its original author, I've drafted a possible solution to tackle the "transactional events" problem.

At the moment it's a draft PR in my Laravel forked repo to first gather feedback from the community before approaching to create an official PR, to give things time to unfold / develop.

I invite everyone to participate in mfn#1 and share your feedback.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants