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

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

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.4fromjwage:fix-doctrine-messenger-pgbouncer
Feb 15, 2024
Merged

[Doctrine Messenger] Fix support for pgsql + pgbouncer.#53819

fabpot merged 1 commit intosymfony:6.4fromjwage:fix-doctrine-messenger-pgbouncer
Feb 15, 2024

Conversation

jwage
Copy link
Contributor

@jwagejwage commentedFeb 7, 2024
edited
Loading

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?no
Issues
LicenseMIT

Problem

When you use PgBouncer in front of a PostgreSQL server with transaction pooling mode enabled, theINSERT and thelastInsertId() happen in separate transactions which are separate connections/sessions when using PgBouncer. So the call tolastInsertId() fails with the following exception:

[Doctrine\DBAL\Exception\DriverException (7)]An exception occurred in the driver: SQLSTATE[55000]: Object not in prerequisite state: 7 ERROR:  lastval is not yet defined in this sessionException trace: at /app/vendor/doctrine/dbal/src/Driver/API/PostgreSQL/ExceptionConverter.php:87Doctrine\DBAL\Driver\API\PostgreSQL\ExceptionConverter->convert() at /app/vendor/doctrine/dbal/src/Connection.php:1938Doctrine\DBAL\Connection->handleDriverException() at /app/vendor/doctrine/dbal/src/Connection.php:1886Doctrine\DBAL\Connection->convertException() at /app/vendor/doctrine/dbal/src/Connection.php:1253Doctrine\DBAL\Connection->lastInsertId() at /app/vendor/symfony/doctrine-messenger/Transport/Connection.php:156Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection->send() at /app/vendor/symfony/doctrine-messenger/Transport/DoctrineSender.php:46Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineSender->send() at /app/vendor/symfony/doctrine-messenger/Transport/DoctrineTransport.php:72Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport->send() at /app/vendor/symfony/messenger/EventListener/SendFailedMessageForRetryListener.php:81Symfony\Component\Messenger\EventListener\SendFailedMessageForRetryListener->onMessageFailed() at /app/vendor/symfony/event-dispatcher/EventDispatcher.php:220Symfony\Component\EventDispatcher\EventDispatcher->callListeners() at /app/vendor/symfony/event-dispatcher/EventDispatcher.php:56Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at /app/vendor/symfony/messenger/Worker.php:198Symfony\Component\Messenger\Worker->ack() at /app/vendor/symfony/messenger/Worker.php:174Symfony\Component\Messenger\Worker->handleMessage() at /app/vendor/symfony/messenger/Worker.php:109

Solution

Wrap theINSERT 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 PostgresSQLRETURNING id clause instead of callinglastInsertId() so we can get the id of the inserted message in one operation instead of two.

TODO:

  • Add test for table not found scenario when inserting a message.
  • Add tests for when lastInsertId returns false, int and string.
  • Is there a place where I can write an integration test for this behavior that already exists?
  • Investigate using pgsql RETURNING clause to simplify this. The insert can return the id after the message is inserted.
  • Squash commits to one clean commit before merge.

dunglas reacted with thumbs up emoji
@jwage
Copy link
ContributorAuthor

I need to work on this some more. Tests are failing.

@jwage
Copy link
ContributorAuthor

I don't think these test failures are related to my changes.

@dunglas
Copy link
Member

For an integration test, you can do something like in#53733.

jwage reacted with thumbs up emoji

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.

Random comments :)

@jwage
Copy link
ContributorAuthor

For an integration test, you can do something like in#53733.

Thanks@dunglas. This was helpful. I was able to add pgbouncer to the integration tests and write a test that runs through pgbouncer.

dunglas reacted with heart emoji

// handle setup after transaction is no longer open
if ($this->autoSetup && $e instanceof TableNotFoundException) {
$this->setup();
goto insert;
Copy link
Member

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

chalasr reacted with thumbs up emoji
@fabpot
Copy link
Member

Thank you@jwage.

dunglas, chalasr, and jwage reacted with hooray emoji

@fabpotfabpot merged commit189bfeb intosymfony:6.4Feb 15, 2024
@jwagejwage deleted the fix-doctrine-messenger-pgbouncer branchFebruary 15, 2024 07:55
This was referencedFeb 27, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@fabpotfabpotfabpot approved these changes

@dunglasdunglasdunglas approved these changes

@chalasrchalasrAwaiting requested review from chalasr

@stofstofAwaiting requested review from stof

Assignees
No one assigned
Projects
None yet
Milestone
6.4
Development

Successfully merging this pull request may close these issues.

7 participants
@jwage@dunglas@fabpot@nicolas-grekas@stof@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp