-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
[Messenger] Break application if the database is not UP #37069
Comments
I have the same issue and same conclusion. |
From my experience, Symfony is quite eager to load services when that wasn't expected. The same issue happened with SNC Redis having no Redis server when building Docker images. The solution there was marking the service as lazy. /cc @B-Galati Same here: Algatux/influxdb-bundle#82 This seems like a systemic problem, TBH. |
The issue is the usage of APIs triggering the DB connection in the transport factory. The factory should not require connecting to the DB. |
@stof could this be solved by adding a tag to specific services and triggering them in boot / cache warmup as an error? To be exact, since the difference between "build" and "cache" was introduced in #36515, there obviously exists "build-time" and "run-time", accessing runtime-only services at build-time should be considered an error. Marking Doctrine connection as such would highlight this issue during development. |
well, here, this should be solved by avoiding to connect to the database in the DoctrineTransportFactory. It should not be calling |
Discussion from Slack:
This instrumentation would mean any runtime-only interaction during build-time would result in an exception. |
Is it wrong to say that |
@dkarlovi IMO, there could be a simpler approach: Moving the connection call on the Connection itself rather than in the factory. IMO the connection could check each time that a query is executed if the database is up (by default, Doctrine call This way, if the database/connection is not up, the connection method call fails and not the connection instantiation. Plus, I agree with @B-Galati that lazy services are already there for solving the concepts that you've listed. |
@Guikingone |
@Guikingone what you describe is solving the consequence, what I'm describing is an attempt to solve the underlying systemic issue which is obvious by the fact the same problem appears over and over. Adding support to recognize it would ensure this stops happening since the framework and bundle maintainers would get an early signal this is happening and adjust their code. Even if the solution is to make it lazy, you need to know you need to make it lazy to begin with. |
Making a service lazy won't solve the issue if you call one of the methods on it, which will trigger the initialization of the proxy. The workaround using lazy is to apply it on the service which performs logic in its instantiation, not on the service connecting to an external resource in its usage. And the proper fix here is to remove such usage from the instantiation. Applying a proxy is only a workaround. |
Correct, there's no panacea here, which is why my suggestion doesn't attempt to find it, it attempts to warn about some sort of a solution being required, the solution would then be done on a case by case basis, but you need to know you need a solution to begin with. |
See #38618 |
…ction (chalasr) This PR was merged into the 5.1 branch. Discussion ---------- [Messenger][Doctrine] Avoid early db access for pgsql detection | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #37069 | License | MIT | Doc PR | - Keeps the connection lazy using an instanceof check on the DBAL driver instead. Commits ------- c4cc4a3 [Messenger][Doctrine] Avoid early db access for pgsql detection
Symfony version(s) affected: 5.1.0
Description
When symfony boot (CLI), the messenger stack is instanciated. And so the transports are instanciated. Then the doctrine transport tries to connect to the DB. And if there are no DB (in CI for example) it crashs !
It was not the case in 4.4.*
We have the following code:
symfony/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/DoctrineTransportFactory.php
Lines 50 to 54 in 608b770
This part of the code
$driverConnection->getWrappedConnection()
callshttps://github.com/doctrine/dbal/blob/18a053ad016207a66937f78f367f900c771aed94/lib/Doctrine/DBAL/Connection.php#L1455-L1460
And so the connection is established. So if the DB server is not available, it crashed.
In my case, it occrus during PHPStan test suite. In that case, we don't have a DB setup'ed so it does not works.
BTW, it occurs on every single command because messenger try load theses information when symfony boot 😬
Here is the full stack trace:
The text was updated successfully, but these errors were encountered: