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
[DoctrineBridge] Idle connection listener for long running runtime #53214
[DoctrineBridge] Idle connection listener for long running runtime #53214
Conversation
07aa62f
to
ba1eefd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few suggestions 🙂
src/Symfony/Bridge/Doctrine/Listener/DoctrineConnectionListener.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Doctrine/Listener/DoctrineConnectionListener.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Doctrine/Listener/DoctrineConnectionListener.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Doctrine/Listener/DoctrineConnectionListener.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Doctrine/Listener/DoctrineConnectionListener.php
Outdated
Show resolved
Hide resolved
Hi, thanks for working on this topic. |
Just reading the code, it adds a lot new stuff which looks like a new feature instead of a bugfix to me |
ba1eefd
to
3ec9cd7
Compare
I agree that a decorator would be better. Also, would it be possible to catch errors and reconnect only in this case instead of triggering a ping? This would remove the performance hit in most cases. @OskarStark the code probably needs to be simplified, but the underlying bug is annoying because it makes Symfony apps unstable when using FrankenPHP, RoadRunner (without the bundle), Swoole etc. The fix should be made at least in the current stable version. |
3ec9cd7
to
24fb643
Compare
@nicolas-grekas @dunglas ok I'll update it and try to decorate the Connection object |
24fb643
to
40d646a
Compare
Thanks for the explanation Kevin 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the approach, because as @nicolas-grekas mentioned, this will keep pinging the DB every request, even if normally request wouldn't need connection. Can't we make this DBAL middleware instead? Middleware would check if any query fails with "DB went away..." error, if so, reset everything and retry.
Also, bear in mind counterpart for messenger is at https://github.com/symfony/symfony/blob/412ea7afcb533b8a7a95e248d741b70fea505350/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php, so this would be a good opportunity to extract common parts into bridge
src/Symfony/Bridge/Doctrine/Listener/DoctrineConnectionSubscriber.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Doctrine/Listener/DoctrineConnectionSubscriber.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Doctrine/Listener/DoctrineConnectionSubscriber.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Doctrine/Listener/DoctrineConnectionSubscriber.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Doctrine/Listener/DoctrineConnectionSubscriber.php
Outdated
Show resolved
Hide resolved
Ok, I'll update then |
40d646a
to
eb35f9d
Compare
@ostrolucky |
27e36c1
to
d8773ac
Compare
I was referring to middlewares that implement |
Any news on this/what's preventing it from being merged? |
d8773ac
to
7791eb2
Compare
src/Symfony/Bridge/Doctrine/Middleware/IdleConnection/Listener.php
Outdated
Show resolved
Hide resolved
b16e918
to
3d2816c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I force-pushed to fix my last comments :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
3d2816c
to
f7cc44e
Compare
Thank you @alli83. |
<element key="time-sensitive"> | ||
<array> | ||
<element key="0"><string>Symfony\Bridge\Doctrine\Middleware\Debug</string></element> | ||
<element key="1"><string>Symfony\Bridge\Doctrine\Middleware\Debug</string></element> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas Isn't Symfony\Bridge\Doctrine\Middleware\IdleConnection
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, PR welcome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 65ccca0
This pull request introduces a solution based on the RoadRunner bundle's Doctrine ORM/ODM middleware https://github.com/Baldinof/roadrunner-bundle/blob/3.x/src/Integration/Doctrine/DoctrineORMMiddleware.php#L22.
It checks the status of Doctrine connection, then if the connection is initialized and connected, it performs a 'ping' to check its viability. If the ping fails, it closes the connection.
linked to doctrine/DoctrineBundle#1739