-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Doctrine Messenger] Fix support for pgsql + pgbouncer. #53819
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
Conversation
I need to work on this some more. Tests are failing. |
I don't think these test failures are related to my changes. |
src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php
Outdated
Show resolved
Hide resolved
For an integration test, you can do something like in #53733. |
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.
Random comments :)
src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php
Show resolved
Hide resolved
...ent/Messenger/Bridge/Doctrine/Tests/Transport/DoctrinePostgreSqlPgbouncerIntegrationTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php
Show resolved
Hide resolved
...ent/Messenger/Bridge/Doctrine/Tests/Transport/DoctrinePostgreSqlPgbouncerIntegrationTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php
Outdated
Show resolved
Hide resolved
// handle setup after transaction is no longer open | ||
if ($this->autoSetup && $e instanceof TableNotFoundException) { | ||
$this->setup(); | ||
goto insert; |
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.
The goto looks ok here, but another option would be to use a loop. This may increase readability (even if it's more a question of personal taste here).
Thank you @jwage. |
Problem
When you use PgBouncer in front of a PostgreSQL server with transaction pooling mode enabled, the
INSERT
and thelastInsertId()
happen in separate transactions which are separate connections/sessions when using PgBouncer. So the call tolastInsertId()
fails with the following exception:Solution
Wrap the
INSERT
andlastInsertId()
with a single transaction, then whenlastInsertId()
is called, it will be within the same session that the message was inserted in.In addition, this PR adds the ability to use PostgresSQL
RETURNING id
clause instead of callinglastInsertId()
so we can get the id of the inserted message in one operation instead of two.TODO: