Review main Merged

94834[FEATURE] Maintain DB connections in Messenger workers

Stefan Bürk CR +2 V +2 Expert +1084 −0 updated 10/08/26, 12:22

Commit message

Long-running Symfony Messenger workers started via
"messenger:consume" keep a PHP process - and its database
connections - alive across many messages. A connection that
stays idle between two messages can be dropped by the server
(for example MySQL's wait_timeout), so the next message fails
with "MySQL server has gone away".

Symfony ships equivalent middlewares, but they live in the
non-vendored symfony/doctrine-bridge and are built around
Doctrine ORM (ManagerRegistry / EntityManagerInterface), so
they cannot be reused with TYPO3's ConnectionPool.

Two native middlewares are added, operating on ConnectionPool:

* DoctrinePingConnectionMiddleware pings each open connection
  with a dummy select before handling a message and closes and
  reconnects a connection that turned out to be stale (DBAL 4
  compatible via the platform dummy select, as Connection::ping()
  was removed in DBAL 4).
* DoctrineCloseConnectionMiddleware closes the open connections
  after a message has been handled - even when handling throws -
  so the next message starts fresh.

Both are registered and active by default and wrap the message
handling (close outermost, ping innermost). They act only on
asynchronous consumption by a worker (a ConsumedByWorkerStamp is
present); a synchronous dispatch - including the SyncTransport -
is passed through untouched. Only connections already open in
the pool are pinged or closed, so no connection is opened just
to maintain it.

Two cancellable PSR-14 events allow listeners to exclude an
individual connection, for example to keep a dedicated
connection open across messages:

* BeforeMessengerDoctrinePingEvent
* BeforeMessengerDoctrineCloseEvent

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Oliver Klee +1
    • Simon Schaufelberger +1
  • Verified V +2 Done
    • Benni Mack +2
    • Oliver Klee +1
    • Maike Kiebele +1
    • Simon Schaufelberger +1
    • core-ci +1 CI

Issues 2

Files 15

Review log 1726

Show 1 earlier messages
  1. Stefan Bürk uploaded patch set 1 07/19/26, 15:32

  1. core-ci voted on patch set 1 V +1 07/19/26, 15:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/104960

  2. Stefan Bürk uploaded patch set 2 V +1 07/19/26, 16:00

  3. core-ci voted on patch set 2 V +1 07/19/26, 16:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/104961

  4. Stefan Bürk uploaded patch set 3 V +1 07/19/26, 16:28

  5. core-ci voted on patch set 3 V +1 07/19/26, 16:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/104962

  6. Stefan Bürk uploaded patch set 4 V +1 07/19/26, 17:31

  7. core-ci voted on patch set 4 V +1 07/19/26, 17:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/104963

  8. Stefan Bürk uploaded patch set 5 V +1 07/19/26, 18:29

  9. core-ci voted on patch set 5 V +1 07/19/26, 18:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/104966

  10. Stefan Bürk wrote 07/19/26, 19:34

    Topic set to messenger
  11. Stefan Bürk rebased onto patch set 6 V +1 07/19/26, 20:38

  12. core-ci voted on patch set 6 V +1 07/19/26, 20:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/104969

  13. Stefan Bürk rebased onto patch set 7 V +1 07/20/26, 13:14

  14. core-ci voted on patch set 7 V +1 07/20/26, 13:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105030

  15. Oliver Klee voted on patch set 7 V +1 07/27/26, 07:51

  16. Stefan Bürk rebased onto patch set 8 V +1 07/28/26, 06:29

  17. core-ci voted on patch set 8 V +1 07/28/26, 06:46 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105517

  18. Stefan Bürk rebased onto patch set 9 V +1 08/01/26, 20:36

  19. core-ci voted on patch set 9 V +1 08/01/26, 20:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105816

  20. Oliver Klee voted on patch set 9 V +1 08/02/26, 08:50

  21. Simon Schaufelberger voted on patch set 9 CR +1 V +1 08/02/26, 09:05

  22. Oliver Klee voted on patch set 9 CR +1 08/17/26, 07:56

  23. Maike Kiebele voted on patch set 9 V +1 08/19/26, 07:27

  24. Benni Mack voted on patch set 9 CR +2 V +2 10/08/26, 12:22

  25. Benni Mack merged patch set 10 10/08/26, 12:22