Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

alli83
Copy link
Contributor

@alli83alli83 commentedDec 26, 2023
edited by nicolas-grekas
Loading

QA
Branch?7.1
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix#51661
LicenseMIT

This pull request introduces a solution based on the RoadRunner bundle's Doctrine ORM/ODM middlewarehttps://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 todoctrine/DoctrineBundle#1739

dunglas, Devristo, cvergne, and DennisdeBest reacted with heart emojimrossard, a1812, dmaicher, and cvergne reacted with eyes emoji
@carsonbotcarsonbot added this to the6.4 milestoneDec 26, 2023
@alli83alli83force-pushed thedoctrine-brige-doctrine-connection-listener-long-running-runtime branch 3 times, most recently from07aa62f toba1eefdCompareDecember 26, 2023 11:53
Copy link
Member

@alexandre-dauboisalexandre-daubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

A few suggestions 🙂

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedDec 26, 2023
edited
Loading

Hi, thanks for working on this topic.
Would there be a way to put that concern in Doctrine itself, by decorating the Connection object?
I'm concerned that the current approach will trigger one DB call per HTTP request while not all HTTP entpoints might use Doctrine, and also by the fact this only works for HTTP while recovering from stalled DB connections is also a concern for CLI workers.

@OskarStark
Copy link
Contributor

Just reading the code, it adds a lot new stuff which looks like a new feature instead of a bugfix to me

@alli83alli83force-pushed thedoctrine-brige-doctrine-connection-listener-long-running-runtime branch fromba1eefd to3ec9cd7CompareDecember 27, 2023 05:15
@dunglas
Copy link
Member

dunglas commentedDec 27, 2023
edited
Loading

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.

@alli83alli83force-pushed thedoctrine-brige-doctrine-connection-listener-long-running-runtime branch from3ec9cd7 to24fb643CompareDecember 27, 2023 06:38
@alli83
Copy link
ContributorAuthor

@nicolas-grekas@dunglas ok I'll update it and try to decorate the Connection object

dunglas reacted with thumbs up emoji

@alli83alli83force-pushed thedoctrine-brige-doctrine-connection-listener-long-running-runtime branch from24fb643 to40d646aCompareDecember 27, 2023 06:44
@OskarStark
Copy link
Contributor

@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.

Thanks for the explanation Kevin 👍

Copy link
Contributor

@ostroluckyostrolucky left a comment
edited
Loading

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 athttps://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

dunglas reacted with thumbs up emoji
@alli83
Copy link
ContributorAuthor

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 athttps://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

Ok, I'll update then

@alli83alli83force-pushed thedoctrine-brige-doctrine-connection-listener-long-running-runtime branch from40d646a toeb35f9dCompareJanuary 3, 2024 06:17
@alli83
Copy link
ContributorAuthor

alli83 commentedJan 3, 2024
edited
Loading

@ostrolucky
Before refactoring (taking into accountDoctrinePingConnectionMiddleware), I'm not entirely sure I grasp the specific middleware you're referring to. Are you referring to those related toDoctrine\DBAL\Driver
Doctrine\DBAL\Driver\Connection

@alli83alli83force-pushed thedoctrine-brige-doctrine-connection-listener-long-running-runtime branch 2 times, most recently from27e36c1 tod8773acCompareJanuary 3, 2024 06:23
@ostrolucky
Copy link
Contributor

I was referring to middlewares that implementDoctrine\DBAL\Driver\Middleware. This is how Symfony does stuff like logging

@KDederichs
Copy link
Contributor

Any news on this/what's preventing it from being merged?

lermontex reacted with thumbs up emojiclussiana, DennisdeBest, and blt909 reacted with eyes emoji

@alli83alli83force-pushed thedoctrine-brige-doctrine-connection-listener-long-running-runtime branch fromd8773ac to7791eb2CompareMarch 12, 2024 04:19
@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.1Apr 25, 2024
@nicolas-grekasnicolas-grekasforce-pushed thedoctrine-brige-doctrine-connection-listener-long-running-runtime branch fromb16e918 to3d2816cCompareApril 25, 2024 09:20
Copy link
Member

@nicolas-grekasnicolas-grekas left a 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 :)

@nicolas-grekasnicolas-grekas added Ready ❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze" labelsApr 25, 2024
Copy link
Member

@dunglasdunglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

🎉

aleho reacted with heart emoji
@nicolas-grekasnicolas-grekasforce-pushed thedoctrine-brige-doctrine-connection-listener-long-running-runtime branch from3d2816c tof7cc44eCompareApril 25, 2024 09:30
@nicolas-grekas
Copy link
Member

Thank you@alli83.

aleho reacted with heart emoji

<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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@nicolas-grekas Isn'tSymfony\Bridge\Doctrine\Middleware\IdleConnection?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oops, PR welcome

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

fixed in65ccca0

@fabpotfabpot mentioned this pull requestMay 2, 2024
$containerMock = $this->createMock(ContainerInterface::class);
$connectionExpiries = new \ArrayObject(['connectionone' => time() - 30, 'connectiontwo' => time() + 40]);

$connectionOneMock = $this->getMockBuilder(ConnectionInterface::class)

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.

Copy link
Contributor

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.

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.

@jsamouh
Copy link
Contributor

jsamouh commentedJan 16, 2025
edited
Loading

possible to backport that into 6.X ? cc@fabpot

@derrabus
Copy link
Member

No, we don't backport features.

@jsamouh
Copy link
Contributor

jsamouh commentedJan 16, 2025
edited
Loading

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

@greg0ire
Copy link
Contributor

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.

derrabus and DavidBadura reacted with thumbs up emojijorgebenzeno reacted with thumbs down emoji

@jsamouh
Copy link
Contributor

jsamouh commentedJan 16, 2025
edited
Loading

I dont agree but if you say so
thks for the response !
Good luck

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@stofstofstof requested changes

@DavidBaduraDavidBaduraDavidBadura left review comments

@greg0iregreg0iregreg0ire approved these changes

@OskarStarkOskarStarkOskarStark left review comments

@andersonamullerandersonamullerandersonamuller left review comments

@alexandre-dauboisalexandre-dauboisalexandre-daubois left review comments

@calinblagacalinblagacalinblaga left review comments

@dunglasdunglasdunglas approved these changes

@ostroluckyostroluckyostrolucky approved these changes

@lyrixxlyrixxAwaiting requested review from lyrixx

@ycerutoycerutoAwaiting requested review from yceruto

@welcoMatticwelcoMatticAwaiting requested review from welcoMattic

@kbondkbondAwaiting requested review from kbond

@chalasrchalasrAwaiting requested review from chalasr

@jderussejderusseAwaiting requested review from jderusse

@xabbuhxabbuhAwaiting requested review from xabbuh

Assignees
No one assigned
Labels
BugDoctrineBridgeReady❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze"Status: Reviewed
Projects
None yet
Milestone
7.1
Development

Successfully merging this pull request may close these issues.

Doctrine left in non-operable state when used with Swoole/FrankenPHP
16 participants
@alli83@nicolas-grekas@OskarStark@dunglas@ostrolucky@KDederichs@stof@greg0ire@jsamouh@derrabus@DavidBadura@andersonamuller@xabbuh@alexandre-daubois@calinblaga@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp