diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:46:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:46:47 +0000 |
commit | 4ada86876033fa171e2896d7e3d3c5645d8062db (patch) | |
tree | f0d1fee61877df200ccfb1c0af58a39cd551fb46 /library/Reporting/RetryConnection.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-reporting-6f6e52922af9d5e1985f6f512f8f7f5144b36ae1.tar.xz icingaweb2-module-reporting-6f6e52922af9d5e1985f6f512f8f7f5144b36ae1.zip |
Adding upstream version 0.10.0.upstream/0.10.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Reporting/RetryConnection.php')
-rw-r--r-- | library/Reporting/RetryConnection.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/library/Reporting/RetryConnection.php b/library/Reporting/RetryConnection.php new file mode 100644 index 0000000..ebadfd2 --- /dev/null +++ b/library/Reporting/RetryConnection.php @@ -0,0 +1,66 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +use ipl\Sql\Connection; + +class RetryConnection extends Connection +{ + public function prepexec($stmt, $values = null) + { + try { + $sth = parent::prepexec($stmt, $values); + } catch (\Exception $e) { + $lostConnection = Str::contains($e->getMessage(), [ + 'server has gone away', + 'no connection to the server', + 'Lost connection', + 'Error while sending', + 'is dead or not enabled', + 'decryption failed or bad record mac', + 'server closed the connection unexpectedly', + 'SSL connection has been closed unexpectedly', + 'Error writing data to the connection', + 'Resource deadlock avoided', + 'Transaction() on null', + 'child connection forced to terminate due to client_idle_limit', + 'query_wait_timeout', + 'reset by peer', + 'Physical connection is not usable', + 'TCP Provider: Error code 0x68', + 'ORA-03114', + 'Packets out of order. Expected', + 'Adaptive Server connection failed', + 'Communication link failure', + ]); + + if (! $lostConnection) { + throw $e; + } + + $this->disconnect(); + + try { + $this->connect(); + } catch (\Exception $e) { + $noConnection = Str::contains($e->getMessage(), [ + 'No such file or directory', + 'Connection refused' + ]); + + if (! $noConnection) { + throw $e; + } + + \sleep(10); + + $this->connect(); + } + + $sth = parent::prepexec($stmt, $values); + } + + return $sth; + } +} |