-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DoctrineBridge] Idle connection listener for long running runtime #53214
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
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
$containerMock = $this->createMock(ContainerInterface::class); | ||
$connectionExpiries = new \ArrayObject(['connectionone' => time() - 30, 'connectiontwo' => time() + 40]); | ||
|
||
$connectionOneMock = $this->getMockBuilder(ConnectionInterface::class) |
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.
You can just do $this->createMock(ConnectionInterface::class)
to spare two lines of code.
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.
Please don't comment on old, already merged PRs. If you feel strongly about this, send a PR instead.
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.
Sure, was just a general suggestion, though.
possible to backport that into 6.X ? cc @fabpot |
No, we don't backport features. |
well, does not seem to be a feature to me as it fix the error connection for long running runtime whis is our case right now in production with frankenPHP worker mode, cc @dunglas |
We understand you are having an issue you would love to solve, but this listener is a new Symfony feature improving your experience with other software (Doctrine + frankenPHP). There was no issue with Symfony, so it's not a bugfix, and it really shows in the diff, which consists in new classes. It also shows in the changelog: "Add support for auto-closing idle connections" Please stop pinging busy people that have bigger fish to fry and start work on upgrading to Symfony 7.1. If that's too much work, you can always copy paste the classes in this PR in your project, and wire them up. |
I dont agree but if you say so |
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