Close connections after every async job that uses the db

This commit is contained in:
Alejandro Celaya
2025-01-27 15:40:15 +01:00
parent f02a8c876c
commit 3372a2a9c8
3 changed files with 8 additions and 2 deletions

View File

@@ -18,7 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
* *Nothing* * *Nothing*
### Fixed ### Fixed
* *Nothing* * [#2341](https://github.com/shlinkio/shlink/issues/2341) Ensure all asynchronous jobs that interact with the database do not leave idle connections open.
# [4.4.0] - 2024-12-27 # [4.4.0] - 2024-12-27

View File

@@ -73,6 +73,9 @@ return (static function (): array {
], ],
'delegators' => [ 'delegators' => [
EventDispatcher\Matomo\SendVisitToMatomo::class => [
EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
],
EventDispatcher\Mercure\NotifyVisitToMercure::class => [ EventDispatcher\Mercure\NotifyVisitToMercure::class => [
EventDispatcher\CloseDbConnectionEventListenerDelegator::class, EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
], ],
@@ -94,6 +97,9 @@ return (static function (): array {
EventDispatcher\LocateUnlocatedVisits::class => [ EventDispatcher\LocateUnlocatedVisits::class => [
EventDispatcher\CloseDbConnectionEventListenerDelegator::class, EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
], ],
EventDispatcher\UpdateGeoLiteDb::class => [
EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
],
], ],
], ],

View File

@@ -11,7 +11,7 @@ class CloseDbConnectionEventListener
/** @var callable */ /** @var callable */
private $wrapped; private $wrapped;
public function __construct(private ReopeningEntityManagerInterface $em, callable $wrapped) public function __construct(private readonly ReopeningEntityManagerInterface $em, callable $wrapped)
{ {
$this->wrapped = $wrapped; $this->wrapped = $wrapped;
} }