From 3372a2a9c886a23de2e873e0990f554b48e83afe Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 27 Jan 2025 15:40:15 +0100 Subject: [PATCH] Close connections after every async job that uses the db --- CHANGELOG.md | 2 +- module/Core/config/event_dispatcher.config.php | 6 ++++++ .../src/EventDispatcher/CloseDbConnectionEventListener.php | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 557f2704..d09a1851 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this * *Nothing* ### 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 diff --git a/module/Core/config/event_dispatcher.config.php b/module/Core/config/event_dispatcher.config.php index 39efa3cb..d146a516 100644 --- a/module/Core/config/event_dispatcher.config.php +++ b/module/Core/config/event_dispatcher.config.php @@ -73,6 +73,9 @@ return (static function (): array { ], 'delegators' => [ + EventDispatcher\Matomo\SendVisitToMatomo::class => [ + EventDispatcher\CloseDbConnectionEventListenerDelegator::class, + ], EventDispatcher\Mercure\NotifyVisitToMercure::class => [ EventDispatcher\CloseDbConnectionEventListenerDelegator::class, ], @@ -94,6 +97,9 @@ return (static function (): array { EventDispatcher\LocateUnlocatedVisits::class => [ EventDispatcher\CloseDbConnectionEventListenerDelegator::class, ], + EventDispatcher\UpdateGeoLiteDb::class => [ + EventDispatcher\CloseDbConnectionEventListenerDelegator::class, + ], ], ], diff --git a/module/Core/src/EventDispatcher/CloseDbConnectionEventListener.php b/module/Core/src/EventDispatcher/CloseDbConnectionEventListener.php index 985b13c2..23f9df1b 100644 --- a/module/Core/src/EventDispatcher/CloseDbConnectionEventListener.php +++ b/module/Core/src/EventDispatcher/CloseDbConnectionEventListener.php @@ -11,7 +11,7 @@ class CloseDbConnectionEventListener /** @var callable */ private $wrapped; - public function __construct(private ReopeningEntityManagerInterface $em, callable $wrapped) + public function __construct(private readonly ReopeningEntityManagerInterface $em, callable $wrapped) { $this->wrapped = $wrapped; }