-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Adding DoctrineClearEntityManagerWorkerSubscriber to reset EM in worker #34156
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
Adding DoctrineClearEntityManagerWorkerSubscriber to reset EM in worker #34156
Conversation
bf118dd
to
9eda8d7
Compare
src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php
Show resolved
Hide resolved
Seems fine to me to add this. |
9eda8d7
to
5c3f338
Compare
👍 I have pretty much exactly this in a project |
@weaverryan should doctrine middleware for same functionality be removed? Because now we are having 2 approaches to do same thing |
Excellent question :). You probably know better than me. I personally think this should be done always and has no downside (well, a few micro-seconds added after handling each message to clear)... so there would indeed be no use-case anymore for the "clear" middleware. Do you agree? |
yes, event subscriber completely replaces middleware, so we can remove it. |
5c3f338
to
a8fe494
Compare
a8fe494
to
e7b9888
Compare
DoctrineClearEntityManagerMiddleware is gone and docs PR added |
Failures unrelated - coming from 4.4 branch |
Thank you @weaverryan. |
…eset EM in worker (weaverryan) This PR was merged into the 4.4 branch. Discussion ---------- Adding DoctrineClearEntityManagerWorkerSubscriber to reset EM in worker | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes & no :) | New feature? | yes | Deprecations? | no | Tickets | Fix #34073 | License | MIT | Doc PR | symfony/symfony-docs#12575 | DoctrineBundle PR | doctrine/DoctrineBundle#1043 Hi! I've seen a few developers get "bit" by an issue recently: after running `messenger:consume`, the 2nd, 3rd, 4th, etc message that are handled are getting out-of-date data from Doctrine. The reason is simple: A) Consume the 1st message, it queries for `Foo id=1` to do something B) 10 minutes go by C) Consume the 2nd message. It also queries for `Foo id=1`, but because this is already in the identity map, Doctrine re-uses the data that is now *10* minutes old. Even though one worker process handles many messages, the system should (as much as possible) isolate each handler from each other. This is one very practical place we can help people. Also, checking the code, I don't think clearing the entity manager will cause any issues for an EM whose Connection has not been "connected" yet (i.e. it will not cause a connection to be established). We would wire this in DoctrineBundle, and could make it disable-able... in case that's something that's needed. Commits ------- e7b9888 Adding DoctrineClearEntityManagerWorkerSubscriber to reset entity manager in worker
…eware (weaverryan) This PR was merged into the 4.4 branch. Discussion ---------- Removing notes about doctrine_clear_entity_manager middleware See symfony/symfony#34156 That class was added in 4.4... then removed for 4.4 - so it was never released. I don't think the new "subscriber" added there needs docs - I'll open a PR in DoctrineBundle so that it's (ideally) enabled by default. I see this more as a bug fix that should... just work without you knowing/caring. Commits ------- fdf457a removing notes about doctrine_clear_entity_manager middleware
Hi!
I've seen a few developers get "bit" by an issue recently: after running
messenger:consume
, the 2nd, 3rd, 4th, etc message that are handled are getting out-of-date data from Doctrine. The reason is simple:A) Consume the 1st message, it queries for
Foo id=1
to do somethingB) 10 minutes go by
C) Consume the 2nd message. It also queries for
Foo id=1
, but because this is already in the identity map, Doctrine re-uses the data that is now 10 minutes old.Even though one worker process handles many messages, the system should (as much as possible) isolate each handler from each other. This is one very practical place we can help people. Also, checking the code, I don't think clearing the entity manager will cause any issues for an EM whose Connection has not been "connected" yet (i.e. it will not cause a connection to be established).
We would wire this in DoctrineBundle, and could make it disable-able... in case that's something that's needed.