Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Messenger] Add a middleware to log when transaction has been left open#41265
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
lyrixx commentedJul 23, 2021
ping @symfony/mergers |
src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionWatchdogMiddleware.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionWatchdogMiddleware.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
e7db3da tod0dbdd0Comparelyrixx commentedJul 23, 2021
@OskarStark Thanks for the review. I added tests + entry in the CHANGELOG. |
d0dbdd0 tobad5019CompareNyholm commentedJul 24, 2021
Thank you for this PR. This scenario seams like an edge case. My experience is obviously biased, but I can count the number of times I've been working with DB transactions on my one hand. Given you have code in your handler that open a transaction, I think that handler should also be responsible to make sure the transaction is closed. I do see the value for a middleware like this in your application or in a third partly library. But I don't think it should be in the Symfony organisation. Im 👎 |
lyrixx commentedJul 25, 2021
Don't get me wrong: this middleware is a watchdog. People should not really on it. As you can see, when it's triggered, it generates anerror log. So yes, all open transaction must to closed in the handler, I agree with you on this point. |
230bede to9929d9cComparelyrixx commentedSep 15, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
People tend to like this feature:https://twitter.com/lyrixx/status/1437440305159094275 andhttps://twitter.com/lyrixx/status/1418497608658661382 Another option would be to throw an exception when the transaction is not finished. |
lyrixx commentedSep 22, 2021
ping@Nyholm ; What do you think ? 👆 |
fabpot commentedSep 22, 2021
First sentence of the description says: "This is a WIP to get some feedback." So, I suppose it cannot be merged yet :) |
lyrixx commentedSep 22, 2021
@fabpot I have edited the PR description, thanks :) |
chalasr commentedSep 22, 2021
I share Tobias's feeling here, the proposed middleware seems too specific for being in core to me (same for the exception alternative). |
lyrixx commentedSep 22, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@chalasr as I explained in the PR description, forgetting to close a transaction can really hurt. IMHO this middleware should be native and not op-tin 😬 I understand your point of view, but as you can see, people on twitter tend to like it 👼🏼 |
chalasr commentedSep 22, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Well, it's less than your average likes on contrib related tweets isn't it? 🙃 Jokes aside, I can see the potential value for debugging so I won't block this PR. |
lyrixx commentedSep 22, 2021
I could just log indeed, without exception, and without throwing. I'll update the PR. |
9929d9c to8a841ceComparelyrixx commentedOct 1, 2021
I updated the PR. now, it only log at |
src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionWatchdogMiddleware.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
OskarStark commentedOct 3, 2021
Maybe "Detect" is more appropriate than "watchdog"? |
8a841ce tod9f31acComparelyrixx commentedOct 4, 2021
I have renamed everything:
|
DoctrineOpenTransactionLoggerMiddlewareDoctrineOpenTransactionLoggerMiddlewaref454955 tofaae1a2Comparefaae1a2 to838846aComparechalasr commentedOct 5, 2021
Thank you@lyrixx. |
Uh oh!
There was an error while loading.Please reload this page.
I notice something that can hurt applications: If one open a transaction
in a handler, but don't close it, the transaction is not close by
Doctrine nor Symfony. So all others messages are still handled in the
transaction. More over, when the retry limit is reach, messenger will
try to save the message in the failed transport. In my case it's
doctrine. So the failed message is save, but inner a transaction. When
the worker stop, the transaction is rollbacked, and so the message is
lost.